(Bowing deeply, rhowerton humbly asks)
My understanding of autoflushing is that if you set $| = 1 then it is supposed to flush after a write (http://www.perlmonks.com/index.pl?node_id=20590), however it does not seem to be working. I am assuming that the print statement is a write and that it should print to the screen immediately upon execution. Here is the script I am trying to get working...understand it has changed many times as frustration has set in.
$|++;
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++;
}
}
}
Thank you in advance,
Ryan