Is SIGPIPE signal received when reader is killed forcefully(kill -9)?

428 Views Asked by At

I have created a fifo using C and python programs. The fifo is created in the C program, which does the reading Operation and the writing is done in Python. My question is as follows:

  1. If my reader(C program) is killed forcefully, my writer keeps writing to the fifo. How can I handle this so that the writer exits when reader is killed?
  2. When the reader is killed , is a SIGPIPE signal recieved by the writer?
2

There are 2 best solutions below

0
ikegami On

When writing to a pipe with a defunct reader, the writer will receive a SIGPIPE signal. By default, this will kill the process. If the signal is ignored, the write will return error EPIPE. This happens regardless of how the reader died.

0
pratibhamenon On

So I observed the following on further testing:

  1. When the reader process is killed, SIGPIPE is not recieved by the writer.
  2. However, when reader is killed, the open call for the fifo file is blocked at the writer's end. So, I have currently resolved the issue in question no.1 by adding O_NONBLOCK flag in my writer's open call. Once this is added, open call throws an exception if the fifo has no active readers. Thanks!