process group = job, and signal question



Hello all,

I have written 2 small programs to test the signal delivering
behaviour

// pipewriter.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

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

int main(void){
char alphabet[] = "abcdefghijklmnopqrstxyz";
int i = 0;
signal(SIGINT, sigint);
while(1){
if(i >= sizeof alphabet)
i = 0;
sleep(1);
printf("%c", alphabet[i++]);
fflush(stdout);
}
return 0;
}

// pipereader.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

char buff[256] = {0};

void sigint(int signum){
printf("reader INT\n");
printf("buffer = %s\n", buff);
exit(0);
}

int main(void){
signal(SIGINT, sigint);
while(1){
fgets(buff, sizeof buff / sizeof buff[0], stdin);
}
return 0;
}

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?

sometimes a program may release resources in the signal handler
not executing all of them would mean resoure leakage, doesn't it?

thanks in advance
Regards, Daniel
.



Relevant Pages

  • Re: signal, parent & children processes
    ... > void sigINT_handler1 ... > signal (SIGINT, sigINT_handler1); ... > but Child doesn't catch SIGINT via sigINT_handler2. ...
    (comp.unix.programmer)
  • Select in child thread
    ... SIGINT is caught in 'thread_fun'. ... which 'select' should unblock when i raise SIGINT for the first time? ... int thread_select; ...
    (comp.unix.programmer)
  • signal, parent & children processes
    ... void sigINT_handler1 ... signal (SIGINT, sigINT_handler1); ... but Child doesn't catch SIGINT via sigINT_handler2. ...
    (comp.unix.programmer)
  • select, signal, thread
    ... SIGINT is caught in 'thread_fun'. ... which 'select' should unblock when i raise SIGINT for the first time? ... int thread_select; ...
    (comp.unix.programmer)
  • Re: signal, parent & children processes
    ... >> Parent catchs SIGINT via sigINT_handler1, ... >> but Child doesn't catch SIGINT via sigINT_handler2. ... >> How can Child catch SIGINT with its own signal handler? ... > void sigINT_handler1 ...
    (comp.unix.programmer)