Answered step by step
Verified Expert Solution
Question
1 Approved Answer
One of your colleagues is thinking of using signals to allow a parent process to count events that occur in a child process. The idea
One of your colleagues is thinking of using signals to allow a parent process to count events that occur in a child process. The idea is to notify the parent each time an event occurs by sending it a signal, and letting the parents signal handler increment a global counter variable, which the parent can then inspect after the child has terminated. However, when he runs the test program in Figure on his system, he discovers that when the parent calls printf, counter always has a value of even though the child has sent five signals to the parent. Perplexed, he comes to you for help. Can you explain the bug?
Figure
#include "csapp.h
int counter ;
void handlerint sig
counter;
sleep;
Do some work in the handler
return;
int main
int i;
SignalSIGUSR handler;
if Fork
Child
for i ; i ; i
Killgetppid SIGUSR;
printfsent SIGUSR to parent
;
exit;
WaitNULL;
printfcounterd
counter;
exit;
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