Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: forking, waiting, and killing child pids

by halfcountplus (Hermit)
on Apr 11, 2012 at 18:48 UTC ( [id://964601]=note: print w/replies, xml ) Need Help??


in reply to forking, waiting, and killing child pids

$snoop in the parent is the child pid. Unfortunately, system() performs a further fork, (and I think tcpdump would be still another child of that) -- and killing the parent doesn't kill the child.

HOWEVER, if you use exec() instead of system(), there are no additional children spawned, so you can stop the process by killing the fork. Just beware, there should not be any calls after exec(), because it doesn't return.

my $pid = fork(); if (!$pid) { exec("tcpdump ..."); # no more code here!!! } sleep(11); kill 9, $pid;

Should work. qv. exec

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://964601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found