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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started