English 中文(简体)
What does SIGPIPE in this situation mean?
原标题:
  • 时间:2009-11-06 14:13:52
  •  标签:
  • perl
  • pipe

I have the following script structure: script A opens PIPE on B, and B opens PIPE on C. So the dataflow is A->B->C. B catches SIGPIPE. Though descriptors IN and OUT are opened:

$SIG{ PIPE } = sub {
$logger->info( caught PIPE signal. );
$logger->info("STDIN status: ".STDIN->opened());
$logger->info("STDOUT status: ".OUT->opened());
die;
};

STDIN status: 1
STDOUT status: 1

I have added IN to the $pool IO::Select and when IN is in the $pool->can_read(), I read from it with sysread(). Once a second I write to OUT with print. Also I have a listen socket in the $pool and clients can connect to it. But I only read from clients. I m writing to OUT only.

问题回答

According to the Wikipedia article, it means that C has died:

On POSIX-compliant platforms, SIGPIPE is the signal sent to a process when it attempts to write to a pipe without a process connected to the other end.

The descriptors will be open even after the process has died. You could, for example, still read things that the program wrote before it died.

However, if you try to write to the dead program, it will throw a SIGPIPE at you.

You can check if a child process is dead by waiting on its PID:

waitpid($childpid, &WNOHANG);

If this returns 0, the child is still running.





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签