Question: use signals to interacting with processes. write a C program sig.c that, when invoked, waits for input from the user and echoes it back line-by-line
use signals to interacting with processes.
write a C program sig.c that, when invoked, waits for input from the user and echoes it back line-by-line (this is the default behavior). This program should execute on a Linux machine, and should be compiled with gcc. While echoing inputs, the program should also listen for several signals. Receipt of each signal should cause a different response from the program.
First, your program should schedule a SIGALRM (alarm) every ten seconds, and react to this signal by counting up seconds, by printing something like the following:
tick 0...
tick 10...
tick 20...
as a running count. This will serve as a "heartbeat" to let you know that your program has not crashed.
Second, the following signals should evoke behaviors as indicated:
SIGINT should print a summary of all time spent by the program (system and user) and then continue running the program.
SIGTERM should print a summary of all time spent in the program, and additionally exit the program
SIGTSTP should print the last 10 lines of user input.
(Hints:
Some documentation exists that may help you. For example;
man signal - how to set up a signal handler.
man sigvec - another way to set up a signal handler.
man sleep - how to use SIGALRM to sleep for a given number of seconds.)
The whole program should be in a single c program sig.c. Programs in other languages are unacceptable. The beginning of the file should describe how to compile the file, in comments.
(A typical compilation command might be: gcc -o sig sig.c)
implement the above using only one signal handler
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
