Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

kill won't kill the process I opened

by useopenid (Initiate)
on Sep 16, 2013 at 03:18 UTC ( #1054213=perlquestion: print w/ replies, xml ) Need Help??
useopenid has asked for the wisdom of the Perl Monks concerning the following question:

I ran into an odd situation in a program I'm writing and wrote this simple test program to show it: when run, it repeats "It's alive!" indicating that kill is failing to kill the process the same program opened. Call me puzzled...
#!/usr/bin/perl use strict; my $stuff_cmd = 'sleep 10'; my $cam_fh; my $cam_pid = open($cam_fh, "$stuff_cmd|"); print "cmd running: $cam_pid\n"; sleep 1; print "killing cmd: $cam_pid\n"; while ((my $count = kill -9, $cam_pid) != 1) { print "It's alive!!!!!\n"; sleep 1; } print "cmd closed off\n"; close($cam_fh); print "dead and buried!\n"; exit 0;

Comment on kill won't kill the process I opened
Download Code
Re: kill won't kill the process I opened
by useopenid (Initiate) on Sep 16, 2013 at 03:33 UTC
    Further info: I modified the "it's alive" to print out $! also and it's getting "No such process", but the process does exist and hasn't switched to any other user:
    $ zt cmd running: 18859 killing cmd: 18859 It's alive!!!!! (No such process) It's alive!!!!! (No such process) It's alive!!!!! (No such process) $ ps aux ... alan 18858 1.0 0.4 5660 1932 pts/2 S+ 20:30 0:00 /usr/ +bin/perl ./zt alan 18859 0.0 0.1 3184 492 pts/2 S+ 20:30 0:00 sleep + 10
Re: kill won't kill the process I opened
by keszler (Priest) on Sep 16, 2013 at 03:34 UTC
    Perl kill != *nix kill. According to kill:

    A negative signal name is the same as a negative signal number, killing process groups instead of processes. For example, kill '-KILL', $pgrp and kill -9, $pgrp will send SIGKILL to the entire process group specified. That means you usually want to use positive not negative signals.
    With kill 'KILL', $cam_pid I got:
    $ ./pm1054213.pl cmd running: 7808 killing cmd: 7808 cmd closed off dead and buried!
Re: kill won't kill the process I opened
by Anonymous Monk on Sep 16, 2013 at 03:40 UTC
Re: kill won't kill the process I opened
by kcott (Abbot) on Sep 16, 2013 at 03:43 UTC

    G'day useopenid,

    I suggest you start by reading the kill documentation.

    A negative signal is for process groups.

    To see whether a process is still running, check the truth of:

    kill 0 => $pid

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1054213]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-09-21 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls