CS计算机代考程序代写 //When CTRL-C is typed, SIGINT is sent to all processes in the

//When CTRL-C is typed, SIGINT is sent to all processes in the
//process group of the terminal’s control process.

#include
#include
#include
#include

void CTRL_handler(int);

void CTRL_handler(int dummy){
printf(“Process %d got a CTRL-C, exit\n”, getpid());
exit(2);
}

int main(int argc, char *argv[]){
int i;
printf(“First process, PID=%d, PPID=%d, PGID=%d\n”, getpid(), getppid(), getpgid(0));

signal(SIGINT, CTRL_handler);

for(i=1; i<=3; i++) fork(); printf("PID=%d PPID=%d PGID=%d\n", getpid(), getppid(), getpgid(0)); pause(); }