Your comments got me thinking about how get_pidof() is implemented and therein lies the solution. get_pidof() uses `ps` and kicks off a child process to execute `ps`. So even when my childcnt is zero, wait() will return a proper pid, not -1.
The solution is to always follow any call to get_pidof() with a call to wait(). That will clear out the pid of the `ps` call.
Just to touch on your other points:
1) I use @ARGV just to enumerate the subprocesses I want to kick off. I invoke fork.pl as `fork.pl a b c` to kick off 3 children.
2) get_pidof() was not picking up the editor running in the background, but it was very astute of you to think of that possibility. That would certainly have wreaked havoc.
3) The `until` loop only decrements childcnt when the return from wait() is
not -1. When wait() returns a -1 the program exits without decrementing childcnt.
Thanks for your help.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.