0% found this document useful (0 votes)
11 views1 page

Conn BTW 2 Process Using Signals

Uploaded by

afrin nisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Conn BTW 2 Process Using Signals

Uploaded by

afrin nisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <signal.

h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

void sighup(int sig);


void sigint(int sig);
void sigquit(int sig);

int main() {
int pid;

if ((pid = fork()) < 0) {


perror("fork");
exit(1);
}

if (pid == 0) { // Child process


signal(SIGHUP, sighup);
signal(SIGINT, sigint);
signal(SIGQUIT, sigquit);

for (;;) {
// Infinite loop to keep child process running
}
} else { // Parent process
printf("\n PARENT: sending SIGHUP \n\n");
kill(pid, SIGHUP);
sleep(3);

printf("\n PARENT: sending SIGINT \n\n");


kill(pid, SIGINT);
sleep(3);

printf("\n PARENT: sending SIGQUIT \n\n");


kill(pid, SIGQUIT);
sleep(3);
}

return 0;
}

void sighup(int sig) {


signal(SIGHUP, sighup);
printf("CHILD: I have received a SIGHUP\n");
}

void sigint(int sig) {


signal(SIGINT, sigint);
printf("CHILD: I have received a SIGINT\n");
}

void sigquit(int sig) {


printf("My Daddy Has Killed Me!!!\n");
exit(0);
}

You might also like