

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Damian-Iordache; Class: Computer Systems II; Subject: Computer Science; University: Villanova University; Term: Unknown 1989;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


This is the fourth piece of the project on process control and signaling. In this assignment you will extend your shell to process signals received from the keyboard. This assignment must be completed individually.
Recall that a signal is a small message that notifies a process that an event of some type has occurred in the system. Typing ctrl-c causes a SIGINT signal to be delivered to each process in the foreground job. The default action for SIGINT is to terminate the process.
Similarly, typing ctrl-z causes a SIGTSTP signal to be delivered to each process in the foreground job. The default action for SIGTSTP is to place a process in the stopped state, where it remains until it is awakened by the receipt of a SIGCONT signal.
if (kill(-pid, SIGINT) < 0) printf("kill (sigint) error");
Here is one problem: When you run your shell from the standard Unix shell, your shell is running in the foreground process group. If your shell then creates a child process, by default that child will also be a member of the foreground process group. Since typing ctrl-c sends a SIGINT to every process in the foreground group, typing ctrl-c will send a SIGINT to your shell, as well as to every process that your shell created, which obviously is not correct. Here is the workaround: After the fork, but before the execvp, the child process should call setpgid(0, 0), which puts the child in a new process group whose group ID is identical to the childs PID. This ensures that there will be only one process, your shell, in the foreground process group. When you type ctrl-c, the shell should catch the resulting SIGINT and then forward it to the appropriate foreground job (or more precisely, the process group that contains the foreground job). Important Note. Do not forget to add SIGINT and SIGTSTP to the mask set of blocked signals before the child gets forked. This eliminates race conditions where the child receives one of these signals before the parent calls addjob.
/*
/* The FG job has completed and been reaped by the handler (^) */ if (!j) return;
/* Busy waiting while there is a FG process (^) */ while (j->pid == pid && j->state == FG) sleep(1);
printf("waitfg: Process (%d) no longer the FG process", pid);
return; }
Your score will be computed out of a maximum of 60 points based on the following distribution:
50 Correctness.
10 Style points. We expect you to have good comments and to check for errors.
Hand in a printed copy of the following:
Make sure you have included your name and your Unix login name in the README file. Leave your source code in your Unix account. Good luck!