rovf has asked for the wisdom of the Perl Monks concerning the following question:
I create processes (on Windows) using something like $pid=system(1,'perl.exe "prog.pl" "x" "y" "z" 2>&1'); (i.e. the command always needs to invoke cmd.exe implicitly - I mention this because it might be relevant to the problem), and from time to time use waitpid($pid,WNOHANG) to poll this process. If waitpid returns -1, I assume that the process has been ended.
This works well so far. However, I now had once the following weird behaviour: waitpid returned -1, but the process terminated 8 seconds later (and actually did useful work during this 8 seconds). I found out because we do plausibility checks: The processes do some logging on their activities, and at the last step, the child process creates a certain file. The main process, after receiving -1 from waitpid, checks for the existence of this file, and issues an error message if this control file does not exist.
In this failure case, I see from the log file of the masterprocess, that at a certain time X waitpid had returned -1, but the control file did not exist, while the log file of the child process asserted that the control file had been created at time X+8 seconds.
From this I conclude that waitpid had signalled the end of the child process while this was still running. Now we know that in order to run the child process, a cmd.exe process must have been created (because the argument passed to system(1,...) uses shell quoting and redirection), and that cmd.exe then in turn creates a process for the command I had passed to system(). We also know that cmd.exe and its sub-process run in the same process group (at least this is how system(1,...) is supposed to work). The symptom I have experienced, looks as if cmd.exe had terminated earlier, before perl.exe "prog.pl".... was finished. This seems bizarre, and makes me a bit nervous. Any explanations for this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: waitpid returns -1 for still running child (Windows)
by BrowserUk (Patriarch) on Jul 06, 2010 at 11:39 UTC | |
by rovf (Priest) on Jul 06, 2010 at 12:21 UTC | |
by BrowserUk (Patriarch) on Jul 06, 2010 at 13:17 UTC | |
by rovf (Priest) on Jul 06, 2010 at 15:03 UTC | |
by BrowserUk (Patriarch) on Jul 06, 2010 at 16:16 UTC | |
|