Link to home
Start Free TrialLog in
Avatar of witty
witty

asked on

Get status of pipe-process

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
ASKER CERTIFIED SOLUTION
Avatar of witty
witty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to drop a note in Community Support saying you'd like this question closed, you can ask for your points to be refunded. I suggest you ask that the question be PAQed, so it will remain searchable if someone has a question like this in the future.