Well first of all congrats to your first posting! It would be easier to read if you'use html tags to format your post. See also the Site How To.To your questions: It is possible to run 4 scripts simultanously by using the fork function. Ifyou are running a unix like OS this should work, i don't know about windows systems though. Back to fork -- er work: The fork function will create a new process and return the process id of the created process - known as child process. The Camel Book states the safest way to check fork for errors: FORK: {
if ($pid == fork){
#deal with the parent process
#pid of child is stored in $pid
}elsif (defined $pid){
#handling child process
#parent pid is available via the getppid function
}elsif ($! =~/No more processes/){
# EAGAIN, this error we should be able to fix
sleep 5;
redo FORK;
} else {
#this should'nt happen at all
die "cannot execute fork: $!\n";
}
Don't forget to do a reset on all your open buffers with setting $|. To avoid Zombies you should wait for your childs to exit. Use always the exit() function to end a process! The function used to wait for a child is as you may have guessed wait wait will wait and return whenever a child process exits. The status of the process is then stored in $? and the return value represents the process id of the exiting child process. If there is no child process at al you will get a -1 back. Another way to avoid Zombies is to install a Signal handler that will take care of you SIGCHLD signals: $SIG{CHLD} = sub(wait); I hope this is enough to get you going. For reference use perldoc -f fork and perldoc -f wait. Regards, C-Keen
Edit by tye |