0

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?
pratibhamenon
  • 363
  • 2
  • 8
  • Why not just write a simple example program to test it to answer it for yourself? – kaylum Jan 10 '22 at 05:22
  • Will definitely try it out. – pratibhamenon Jan 10 '22 at 05:25
  • After that you can post the answer to your own question :-) – kaylum Jan 10 '22 at 05:27
  • You should show your code. If the reader is the only process with the FIFO open for reading, then the writer should be signalled with SIGPIPE immediately when attempting to write — beware buffered I/O which may delay the time when the `write()` system call is actually called. If the writer is ignoring SIGPIPE, then the write() system call will return with an error condition. If there are multiple processes with the FIFO open for reading, then _all_ readers have to die before the writer(s) get signalled. – Jonathan Leffler Jan 10 '22 at 05:46

2 Answers2

0

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.

ikegami
  • 367,544
  • 15
  • 269
  • 518
0

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!
pratibhamenon
  • 363
  • 2
  • 8