rhowerton has asked for the wisdom of the Perl Monks concerning the following question:
Thank you in advance,$|++; open(TCPDUMP,"/usr/sbin/tcpdump -i eth0:1 port 80 -s 60 -xX | grep GET + |") or die "Could not run command: $!"; my $DEBUG = 1; my $sleepTime = 5; my $count = 0; my $sleepCheck = 0; while(<TCPDUMP>) { chomp($_); print "$_\n"; FORK: { if($sleepCheck == 0) { if (my $pid = fork) { # parent here # child process pid is available in $p +id $count++; } elsif (defined $pid) { # $pid is zero here if defined # child here # parent process pid is available with + getppid $sleepCheck = 1; sleep($sleepTime); open(DUMPLOG, "> ./dump.log") or die " +Could not open dump log: $!"; print DUMPLOG "$count\n"; print "$count\n"; close(DUMPLOG); $sleepCheck = 0; $| = 0; exit(0); } elsif ($! == EAGAIN) { # EAGAIN is the supposedly recoverable + fork error if($DEBUG == 1) { print "Error: $!.\n"; } sleep 5; redo FORK; } else { # weird fork error die "Can't fork: $!\n"; } } else { $count++; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Autoflushing revisited.
by pzbagel (Chaplain) on Jul 11, 2003 at 16:31 UTC | |
|
Re: Autoflushing revisited.
by tedrek (Pilgrim) on Jul 11, 2003 at 16:35 UTC | |
|
Re: Autoflushing revisited.
by graff (Chancellor) on Jul 11, 2003 at 23:44 UTC |