SavannahLion has asked for the wisdom of the Perl Monks concerning the following question:
FORK: { if ($pid = fork) { #Parent here. #Child process pid is available in $pid } elsif (defined $pid) { #pid is zero here if defined #child here #parent process pid is available with getppid (Not available wit +h Windows). } elsif ($! == EAGAIN) { #EAGAIN is supposedly recoverable fork error sleep 5; redo FORK; } else { #Weird fork error die "Can't fork: $!\n"; } }
No problem with two things. But how do I get three going? So I looked around and figured maybe I should create a pipe the forked children and tell it what I want it to do (two of the processes launch help apps, so they use the same generic code). So I looked in the camel and located the following snippet:
OK. So, put my pieces together, run script and it dies with, "Bad command or file name."if (open(TO, "|-")) { print TO $fromparent; } else { $tochild = <STDIN>; #Do whatever with $child exit; };
So then I tried "Pipe Child" and "Pipe STDIN" and couldn't discover the little nugget.
I did however, find a hint, "pipe," and I think I can utilize this to communicate to my children. Problem is, I'm not sure how this is done. The format follows something like, pipe READHANDLE,WRITEHANDLE. I figure I could use the $pid of the child, but what do I used for the WRITEHANDLE?
Again, the Camel has another example on how to use Pipe to communicate with children. I type the code example in the book to open a pipe to my child:
And the Perl script dies with a "Not enough arguments for select system call" along with a syntax error.... grrr.....pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!"; select((select(TO_CHILD), $| = 1))[0]);
----
Thanks for your patience.
Prove your knowledge @ HLPD
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: open(TO, "|-") is a bad file name?
by ysth (Canon) on Feb 24, 2004 at 03:41 UTC | |
by SavannahLion (Pilgrim) on Feb 24, 2004 at 05:56 UTC | |
by ysth (Canon) on Feb 24, 2004 at 16:34 UTC | |
|
Re: open(TO, "|-") is a bad file name?
by BUU (Prior) on Feb 24, 2004 at 08:02 UTC | |
|
Re: open(TO, "|-") is a bad file name?
by promethyl (Initiate) on Feb 25, 2004 at 16:51 UTC |