Re: process group = job, and signal question




Schüle Daniel wrote:
// pipewriter.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

void sigint(int signum){
printf("writer INT\n");
exit(0);
}

A small, somewhat pedantic point that is not
relevant to this example, but is an important piece
of information: this is unsafe. You cannot reliably
call printf from your signal handler. See signal(2)
for more information.
<snip>

finally I let pipewriter write into the pipe

./pipewriter | ./pipereader

and after 7 seconds I send SIGINT (type cntr-Z in terminal)
this is the message I see

reader INT
buffer = abcdefg


well, does this mean that only last process in the pipe
executes its "sigint" handler?
does it become process leader?

No. It means that pipewriter wrote it's message into the
pipe, but didn't flush it. But ctrl-z doesn't send SIGINT, that's
ctrl-C, so I'm not sure exactly what you did. The problem
you're seeing is probably just a result of failing to flush
the buffers, and then stopping your test too early.

.



Relevant Pages