Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions