in reply to Re: get_pidof() messes with wait()?
in thread get_pidof() messes with wait()?

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.