ASSIGNMENT 2

The purpose of this assignment is to get students comfortable with the use of fork and signals.

What needs to be submitted:


Your program must do the following:

1. Open a file for writing using the system call open.

2. Create a new process by using the fork system call.

3. The parent and child must write to the file strictly alternately - first, the parent writes and then the child writes - for a total of 10 times each. Parent writes the string "Parent Process (i, pid, childpid)" and Child writes the string "Child Process (i, pid, parentpid)", where i is the iteration value represented by a local variable declared in the main() of the program.

NOTE1: DO NOT OPEN THE FILE AGAIN IN THE CHILD. Remember that open file descriptors are inherited by the child from its parent.

NOTE2: PLEASE NOTE THAT YOU MUST ACHIEVE SYNCHRONIZATION USING BOTH THE signal and pause system calls as well as sigaction and related system calls.

QUESTION: Is this possible at all using signal system call?

Include a README in the submission that comments on the observed output while using the signal versus the sigaction system calls. Explain any unreliability you notice with the signal system call - i.e., why do you think your output is the way it is - what sequence of parent and child execution could have caused this unreliability?

4. Your program should NOT result in either a zombie or an orphan process.