Hi!
I want to use a perl-program to check, whether a program, that feeds a pipe (endless loop) is running or not:
I would use something like:
------------
die "FIFO is no pipe\n" unless (-p "fifo.txt");
$SIG{ALRM} = sub {
print "Process does NOT feed the pipe!!!\n";
open(WRITER,">fifo.txt");#
make the program end properly -> write to pipe myself <- this does not work?????
print WRITER "ALARM!\n";
close(WRITER);
};
alarm(3);
open(READER,"fifo.txt");
while (<READER>){
}
close(READER);
alarm(0);
--------
why does this not work???
another idea:
--------
die "FIFO is no pipe\n" unless (-p "fifo.txt");
if ($pid = fork()) {
sleep 3;
kill($pid); #kill child
}else{
open(FIFO,"fifo.txt");
while (<FIFO>){
}
close FIFO;
print "PIPE is OK!\n";
exit;
}
-------
but killing the child would only make the parent exit, but if the pipe is fed afterwards, the child would say "OK"!
any idea how to make this?
thx
michi
Start Free Trial