You ask
I've been working with fork(), and kill in an attempt to resolve a problem with a `lynx -source $page` hanging periodically. I thought from various docs that my $result = kill 0, $pid; would tell me if the child process was running or done. But alas the result is always 1. How do I get around this? Claude
perldoc -f kill says:
kill SIGNAL, LIST
Sends a signal to a list of processes. Returns the number of
processes successfully signaled (which is not necessarily the
same as the number actually killed).
$cnt = kill 1, $child1, $child2;
kill 9, @goners;
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 the perlport manpage for notes on the portability
of this construct.
Unlike in the shell, if SIGNAL is negative, it kills process
groups instead of processes. (On System V, a negative *PROCESS*
number will also kill process groups, but that's not portable.)
That means you usually want to use positive not negative
signals. You may also use a signal name in quotes. See the
section on "Signals" in the perlipc manpage for details.
so then I
perldoc perlport, and it says:
kill SIGNAL, LIST
Not implemented, hence not useful for taint checking. (Mac OS, RISC OS)
kill() doesn't have the semantics of raise(), i.e. it doesn't send a signal to the identified process like it does on Unix platforms. Instead kill($sig, $pid) terminates the process identified by $pid, and makes it exit immediately with exit status $sig. As in Unix, if $sig is 0 and the specified process exists, it returns true without actually terminating it. (Win32)
So now you have to ask yourself what OS you are on?
It would appear your process is not done (i realize you know).
As far as I can see, you can't get around it (it's not quite a zombie). If you're doing any kind of forking, i'd really reccomend Parallel::ForkManager.
Also, check out perlipc and perlfork (if you have it).
This has been an excursion into the world of pod, click here for the friendly guide (If it's got no pod, throw it out -- podmaster).
| [reply] [Watch: Dir/Any] |
It may be true because you're making zombies.
To know when a child exits, install a SIGCHLD handler. If you set $SIG{CHLD} = 'IGNORE'; the kill trick will work. kill 0, $pid; is more useful for confirming the child has started, right after the fork. The wait or waitpid calls are often used, but since you're debugging a stuck process they are not suitable for you in the body of your program.
If you still are running when the child exits, the child's process hangs around until you read it or say you don't want it. Thus are born zombies if you dont handle them.
After Compline, Zaxo
| [reply] [Watch: Dir/Any] [d/l] [select] |
This is telling you. Read the entry for kill in perlfunc. The return value is the number of processes that would have received the signal. Since you are only test-killing one, the answer would only ever be 0 or 1. Getting back 1 means that the process ID in $pid is still alive (albeit perhaps frozen), and hasn't changed its UID (so you can still send it signals).
--rjray
| [reply] [Watch: Dir/Any] |
It really depends on your operating system. In most Unix variants, this will only tell you if a process with the given pid exists in the process table, not whether it's doing anything. In other words, it will return true unless and until the process in question exits.
I'm not sure if it's the same on Win32, but I suspect it is.
| [reply] [Watch: Dir/Any] |