Sale!

ECE357:Computer Operating Systems PS 4 solution

$30.00 $25.50

Category:

Description

5/5 - (2 votes)

Problem 1 — Signal Numbers
In the questions below, answer both in terms of symbolic signal names (such as SIGSTOP) and the specific signal
number on your system. Be sure to mention what type of UNIX (e.g. BSD, Linux) you are running, what architecture,
and what kernel version.
a) Which signal is delivered to all foreground processes attached to a terminal session when that terminal receives a
Control-C character?
b) If we wanted to stop a program running in the foreground AND cause it to dump core (if possible), what key
sequence do we use?
c) What signal is delivered to the following program:
main()
{
*(int *)0 = 1;
}
d) Which signals are un-ignorable and un-blockable?
e) Go back over items a-d and mark which ones are “Synchronous” vs “Asynchronous”
Problem 2 — Do Signals Count?
Below we hav e a program which asks the question “do signals count?” Type the program in and run it.
a) There are 3 places in the code where I’ve asked a question in the comment. Answer each question:
b) What are your observations on the number of signals received? Explain what is happening.
ECE357:Computer Operating Systems PS 4/pg 2
c) Now replace SIGUSR1 with SIGRTMIN and repeat the experiment. What do you see now and why?
#include
#include
#include
#include
#include
int signo,nsig,counter;
int rcvr_pid;
void handler(s)
{
if (s==signo)
counter++;
}
int main(ac,av)
char **av;
{
struct sigaction sa;
int pid,status,nchild,i;
signo=SIGUSR1;
nsig=10000;
rcvr_pid=getpid();
sa.sa_handler=handler;
/* WHAT would happen if I forgot this line below? */
sa.sa_flags=0;
/* or this line below? */
sigemptyset(&sa.sa_mask);
if (sigaction(signo,&sa,0)== -1)
{
perror(“sigaction”);
return -1;
}
switch(pid=fork())
{
ECE357:Computer Operating Systems PS 4/pg 3
case -1:
perror(“fork”);
return -1;
case 0:
sender();
return 0;
}
fprintf(stderr,”Waiting for sender\n”);
/* WHY do I have this thing with EINTR below?? */
while (wait(&status)>0 || errno==EINTR)
;
printf(“stderr,Received a total of %d of signal #%d\n”,counter,signo);
}
sender()
{
int i;
for(i=0;i