Solved

Get status of pipe-process

Posted on 2003-10-28
3
897 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:witty
3 Comments
 
LVL 1

Accepted Solution

by:
witty earned 0 total points
Comment Utility
I found the answer myself:

die "FIFO is no pipe\n" unless (-p "fifo.txt");

my $pipeok=1;

$SIG{ALRM} = sub {
  if ($pid=fork()){
    `echo XXX > fifo.txt`;
    exit(0);
  }
  $pipeok=0;
};

alarm(3);
open(READER,"fifo.txt");
while (<READER>){}
close(READER);
alarm(0);
if ($pipeok){
  print "PIPE OK!\n";
}else{
  print "PIPE NOT OK!\n";
}
0
 
LVL 20

Expert Comment

by:jmcg
Comment Utility
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now