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
In reply to open(TO, "|-") is a bad file name? by SavannahLion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |