Solved

Get status of pipe-process

Posted on 2003-10-28
3
932 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

726 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