in reply to Forking hell
What is this good for ?
Imagine you want to do several things at one time.
For example to count forward from 1 to 10 and at the same time backward from 10 to 1.
So you start like this:
OK this is done one after the other in one processfor ($i=1;$i<=10;$i++) { print "$i\n" }; for ($j=10;$j>=1;$j--) { print "$j\n" }; # This will give you: 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
To do it at the same time you can use fork:
$pid = fork(); if (! $pid) { ### This is the new process for ($j=10;$j>=0;$j--) { print "$j\n" }; } else { ### This is the parent process for ($i=1;$i<=10;$i++) { print "$i\n" }; }
Now you can do whatever you want in the if (! $pid) part.
It's important that all the vars declared and filled before the fork from the parent process are also available in the child process, but they are not visible in the other process!
Hope this makes it a bit more clearer, but I'm not sure :-)
----------------------------------- --the good, the bad and the physi-- -----------------------------------
|
|---|