in reply to Reminder program
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Running more than one process (the very basics)
by bsdbudha (Initiate) on Oct 02, 2001 at 01:41 UTC | |
by C-Keen (Monk) on Oct 02, 2001 at 01:52 UTC | |
by bsdbudha (Initiate) on Oct 03, 2001 at 02:11 UTC | |
by C-Keen (Monk) on Oct 03, 2001 at 18:16 UTC |