By using C++ code to answer Using signals and an area of shared memory have two
ID: 3693910 • Letter: B
Question
By using C++ code to answer
Using signals and an area of shared memory have two processes synchronize the
processing of a file. The first process should read the file in blocks of 4096 characters
and place them in the shared memory. When the buffer is full it should signal the
second process using SIGUSR1 or SIGUSR2 that the block is ready. Once the
second process processes the characters (in this case it should just transfer them to a
local block of memory) it should signal the first process using the SIGUSR1 or
SIGUSR2. You will also need to signal the other process when the file is completely
read.
Explanation / Answer
SIGUSR1 User defined signal SendMessage–WM_APP SIGUSR2 User defined signal SendMessage–WM_APP #include #include #include The intrpt function reacts to the signal passed in the parameter signum. This function is called when a signal occurs. A message is output, then the signal handling for SIGINT is reset (by default generated by pressing CTRL-C) back to the default behavior. void intrpt(int signum) { printf("I got signal %d ", signum); (void) signal(SIGINT, SIG_DFL); } /* main intercepts the SIGINT signal generated when Ctrl-C is input. Otherwise, sits in an infinite loop, printing a message once a second. */ int main() { (void) signal(SIGINT, intrpt); while(1) { printf("Hello World! "); sleep(1); } } 2. #include #include #include void intrpt(int signum) { printf("I got signal %d ", signum); (void) signal(SIGINT, SIG_DFL); } /* main intercepts the SIGINT signal generated when Ctrl-C is input. Otherwise, sits in an infinite loop, printing a message once a second. */ void main() { (void) signal(SIGINT, intrpt); while(1) { printf("Hello World! "); Sleep(1000); } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.