Question: use signals to interacting with processes. write two C program sig.c that 1.implement using only one signal handler routine to catch all kinds of signals

use signals to interacting with processes.

write two C program sig.c that

1.implement using only one signal handler routine to catch all kinds of signals

2.implement using as many handlers as you choose.

when invoked, waits for input from the user and echoes it back line-by-line (this is the default behavior). These two programs should execute on a Linux machine, and should be compiled with gcc. While echoing inputs, the programs should also listen for several signals. Receipt of each signal should cause a different response from the program.

First, the programs 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.

Third, use the folllowing documentation:

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. 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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!