Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get status of pipe-process

Posted on 2003-10-28
3
Medium Priority
?
945 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 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…
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…
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

610 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