mike928 has asked for the wisdom of the Perl Monks concerning the following question:
Hi there!
I want to write a script that
- captures the output of tcpdump
- deposits the PID of the tcpdump process in $pid
- kills the tcpdump after some time
I tried running this code:
#!/usr/local/bin/perl -w use warnings; use strict; $|=1; my $output; my $pid; $pid = open (STDIN,"sudo /usr/sbin/tcpdump -n -e -i mon_wlan0 -c 100|" +); while ($output=<>){ print "$output\n"; } print "pid = $pid\n";
while running top | grep tcpdump on another terminal
but the PID returned by the script is different(larger) from the one in the terminal
So my questions are:
---why do i have 2 process id-s? (parent&child maybe?)
---how do i fix the script to be able to stop the tcpdump with kill -9 $pid before the packet counter expires ?
Any help would be appreciated. Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: capture output of tcpdump and PID
by thargas (Deacon) on May 22, 2012 at 18:48 UTC | |
by mike928 (Initiate) on May 24, 2012 at 14:38 UTC | |
by aaron_baugher (Curate) on May 24, 2012 at 18:29 UTC | |
by thargas (Deacon) on May 25, 2012 at 11:30 UTC | |
|
Re: capture output of tcpdump and PID
by zentara (Cardinal) on May 22, 2012 at 21:00 UTC |