One method is to keep pipes open to the children - if you have a pipe which the parent reads and the child writes, you can send your dots (valid progess indicators :) down the pipe. You then remove file locking problems (which you have with writing dots to a file). You end up with a parent with a whole bunch of pipes - just do a select() on these, and you'll get woken up whenever there's anything to read from them.
Pipes were pretty much invented for this - they survive fork (i.e., both child and parent can still see it!). Pipes rock :) Programming Perl has some other good examples of IPC - shared memory, sockets, etc., but all that's a bit overboard for what you want. The usual pipe way is:
pipe(READHANDLE, WRITEHANDLE); my $result = fork(); if ($result>0) { # child process, we write to the pipe } else { # parent process, or error - might want to check before # we try to read from pipe :)) }
If you want more than one child, just keep the handles in an array so you don't lose them, and do a select() in the parent when all the children are active.
Oh, and beware of buffering - probably best to turn that off when debugging :)
In reply to Re: Using signals in Perl
by kal
in thread Using signals in Perl
by leons
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |