?
Solved

Get status of pipe-process

Posted on 2003-10-28
3
Medium Priority
?
938 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
witty earned 0 total points
ID: 9638341
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
ID: 9638427
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

801 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