fletcher_the_dog has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that launches an application and then monitors to see if the application is has been closed. Here is a greatly simplified version:
If SIGNAL is zero, no signal is sent to the process. This is a useful way to check that the process is alive and hasn't changed its UID. See perlport for notes on the portability of this construct.
So I thought "kill" would be a good way to see if the process was still going, but it doesn't appear to work. What am I missing? Is there a better way to do this?
The problem is that even after the child process is dead the parent process keeps going. According to the documentation for kill:use strict; my $pid = fork(); if (!$pid) { print "I am the child process\n"; system "emacs"; # this is just an example I am not really launching +emacs print "Child process should end now\n"; exit 0; } else { print "I am the parent of $pid\n"; while (kill 0,$pid) { print "My child is still alive\n"; sleep(3); # wait a little bit } print "Parent process done\n"; } __OUTPUT__ $ perl script.pl I am the child process I am the parent of 1324 My child is still alive My child is still alive My child is still alive Child process should end now My child is still alive My child is still alive etc.
If SIGNAL is zero, no signal is sent to the process. This is a useful way to check that the process is alive and hasn't changed its UID. See perlport for notes on the portability of this construct.
So I thought "kill" would be a good way to see if the process was still going, but it doesn't appear to work. What am I missing? Is there a better way to do this?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using 'kill' to see if a process is stil alive
by Zaxo (Archbishop) on Jul 29, 2004 at 19:22 UTC | |
Re: Using 'kill' to see if a process is stil alive
by ambrus (Abbot) on Jul 29, 2004 at 19:05 UTC |
Back to
Seekers of Perl Wisdom