sinmissing has asked for the wisdom of the Perl Monks concerning the following question:
I've read a variety of docs and examples for how to fork processes, how to get the child pid, and how to kill a pid. I haven't found the right example that illustrates what I wish to accomplish.
My platform is redhat. What I'm attempting to accomplish is this:
fork this process to the background "tcpdump -ni int0 -c 5 -w /tmp/somefile"
sleep while the child process completes, or kill it if it is running longer than 10 seconds ( eg: tcpdump doesn't capture any data ).
my sample code looks like this:
I should add, that I don't have an option for using specific perl modules to enhance by capabilities here.use POSIX; $SIG{CHLD} = 'IGNORE'; my $snoop = fork(); if ( $snoop == 0 ){ setpgrp; system("tcpdump -ni int0 -c 5 -w /tmp/somefile &"); } my $sleeper = 0; while ( $sleeper < 11 ){ # How do I check the status of my child pid? I don't want to wait +for it to finish, just know if it is still running and 'last;' if not +. sleep 1; $sleeper++ } # Only kill the child pid, if it is running. need help here. kill -1, getpgrp($snoop); # continue on with my code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forking, waiting, and killing child pids
by Eliya (Vicar) on Apr 11, 2012 at 21:12 UTC | |
by sinmissing (Initiate) on Apr 20, 2012 at 15:47 UTC | |
|
Re: forking, waiting, and killing child pids
by halfcountplus (Hermit) on Apr 11, 2012 at 18:48 UTC | |
|
Re: forking, waiting, and killing child pids
by eyepopslikeamosquito (Archbishop) on Apr 12, 2012 at 02:23 UTC | |
|
Re: forking, waiting, and killing child pids
by Anonymous Monk on Apr 12, 2012 at 00:18 UTC |