in reply to Running external process WHILE exiting/returning
I think you are mixing exec and fork terminology. First off, in your question you talk about the "parent process" of the exec. That's not how it works. When you fork, a child process is created which is identical to the parent. It is upto your script, through evaluating the return value of the fork(0 for child, pid of child for parent, and undef for failure), to figure out which you are and act according. In the case of exec, the process which performs the exec literally gets overwritten by the program specified in the exec. It comes to a dead stop , it does not continue to run, it will not run "exit" or "return" because it ceases to exist.
Now onto your code. In your code it is a little clearer that you are trying to do a fork and exec. You need to split up your code a little differently:
FORK: { $child=fork; if(defined($child)) { if($child = 0) { my $exec = "/usr/local/bin/monster -i$id $filePath$file &"; qx/$exec/; } } elsif ($! == EAGAIN) { sleep 5; redo FORK; } else { die "Can't fork: $!\n"; } } return 0;
Notice that if $child is defined you check if you are in fact the child process and then you do the exec. If you happen to be the parent process you drop through the if and end up at the return statement, although you could put that in as an else clause of the if ($child=0) statement.
Check out perlipc for more info about fork and exec.
HTH
Addendum - I noticed you are using the qx() quoting characters. These are equivalent to backticks(``) in perl and do not do the same thing as exec. You should probably change qx to an exec call instead to get it to do what you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Running external process WHILE exiting/returning
by seaver (Pilgrim) on Jun 05, 2003 at 21:29 UTC |