As you might be knowing the signal SIGPIPE is sent to the process which is trying to write into a pipe which has no readers.
In your case, to identify the exact pipe which is closed probably you can do the following:
- ignore the SIGPIPE signal i.e.
Code:
signal(SIGPIPE,SIG_IGN); //ignoring the broken pipe signal
- now whenever a reader process exits, since writer process has opted to ignore the signal whenever writer tries to write into the pipe the "write" system call will fail & returns error (-1). The exact reason for the failure of "write" can be got if required ("errno" will be set to "EPIPE").
Hope this will solve your problem.