1st Homework Assignment


Please answer the following questions and explain the reasons for your answers in detail. You will turn in your homework answers handwritten (in ink) or printed on an A4 paper. The due date for this assignment is the 13th of November 2009.

  1. Compile and run prog1.c. Observe and comment on the process id numbers (pid) and the order of the messages output to the screen.
  2. Modify the source code of prog1.c and add the necessary code line for the parent process to also output the pid of its parent process on the screen. Compile and run the new program. Observe and comment on the pid of the parent's parent process.
  3. Remove the wait(NULL) code line from prog1.c. Compile and run the new program. Observe and comment on the parent pid output to the screen by the child process.
  4. Declare a global integer variable at the beginning of prog1.c and initialize it to a value before the fork system call. Output the current value of this variable to the screen both in the parent and the child process. Assign different values to the variable in the parent and the child process separately. Output the new values of this variable to the screen in both processes. Observe and comment on the values output to the screen by the processes.
  5. Declare a global, integer pointer variable and allocate memory for this pointer at the beginning of prog1.c. Assign a value to the location pointed to by the pointer and output the current adress value of the pointer and the current contents of this location to the screen both in the parent and the child process after the fork system call. Assign different values to the locations pointed to by the pointers in the parent and the child process seperately. Output the current adress values of the pointer and the current contents of the location to the screen both in the parent and child process. Observe and comment on the address and memory contents values.