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
In reply to forking, waiting, and killing child pids by sinmissing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |