> The fork concept can be quite confusing at first, but it is actually > quite simple, once you get used to it. Check out the output of this > little program:
[ very interesting stuff cut out ] Wild! Why would anyone ever use this? Why would you ever want to clone yourself at the current point and have both continue on running? I guess I could see it being a smooth way to process a hundred files all at once (sort-of)... I don't get it. [ more interesting stuff cut out ] > with '&' your program won't wait for the other-program to finish, but > the other-program process will die when your program (the parent > process) finishes. Why is this? Does that mean if I create a new tcsh shell, run an app, kill the tcsh shell before the app finishes, that the app will die too? Why have parent/child relationships in processes? Are there such things as grandchildren/grandparents? > Of course you want your program to finish without killing the child > processes in the process (pun definitely intended) and for that you need > your child processes to create new sessions with setsid(). What is a session? I've never heard of that... > You can take a look at Proc::Daemon module on CPAN, but it's not exactly > what you need, mostly because it redirects STDOUT to /dev/null, while > you want your processes to write to STDOUT (by the way, are you sure > about that? it can result in a total mess printed on your terminal) but > still you may want to read its source to see how it works: > http://search.cpan.org/src/EHOOD/Proc-Daemon-0.03/Daemon.pm Yes, I absolutely want all output going to STDOUT. Thanks for foreseeing a potential problem, though... > use POSIX 'setsid'; > sub forkrun ($) { > my $cmd = pop; > defined(my $pid = fork) or die "$0: fork: $!\n"; > unless ($pid) { > setsid or die "$0: setsid: $!\n"; > exec $cmd; > } > return $pid; > } Yes! This works terrifically! How does the fork part work within subroutines? I'm guessing the part starting with "unless" looks to see if it's now a child process, and if so, to quit the current perl script and start off $cmd. Is that right? It works, so that part's taken care of. Now I just have to figure out how it works. =) Thanks a lot zsdc. - Bryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]