Question: write comments to each line of code #include #include #include #include #include #include int flag = 0 ; static void handler(int sig){ if(sig == SIGINT){

write comments to each line of code

#include #include #include #include #include #include

int flag = 0 ; static void handler(int sig){

if(sig == SIGINT){ printf(" Parent PID[%d] Has been Killed!!! ",getppid()); kill(getppid(),SIGKILL); //flag = 1; } }

int main(int argc, char* argv[]){ pid_t pid;

pid = fork();

if(pid==-1){ perror("Failed to create Child using fork() "); exit(EXIT_FAILURE); }else if(pid == 0){ sigset_t sigset; struct sigaction sa; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask,SIGUSR1); sigaddset(&sa.sa_mask,SIGUSR2); sa.sa_sigaction = (void*)&handler; sigprocmask(SIG_BLOCK,&sa.sa_mask,NULL); sigaction(SIGINT,&sa,NULL); while(!flag); }else{ printf(" I am Parent PID[%d] and PPID[%d] showing this before wait() ",getpid(),getppid()); wait(NULL); printf("Parent: After child's termination ");

} return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!