ADOS: ASSIGNMENT 1


There are five questions in this assignment. Answer all of them.

Submission Instructions:

  1. Programs should be in individual files named according to the question numbers.
  2. Explanations should be in either a single PDF or .docx file
  3. Tar all the files, compress it and create a single tgz file with your Roll Number as the filename
  4. Email the compressed tar file to chakcs@dcis.uohyd.ernet.in Email to any other address is not allowed.
  5. Email subject line MUST include the phrase ADOS ASSIGNMENT-1

QUESTIONS

  1. Given this program, guess what its output will be. Then, run the program and see if the output matches the guess. Explain clearly your guess and the output
  2. For the same program as above, what happens if we remove the "break" statement? In this case, also remove all the code from lines 19 - 25. Guess the output and compare it against that after running the program. Explain the output.
  3. Write a program using fork() to create a child process. The program takes three command line arguments. argv[1] is the name of a standard Linux command and argv[2] is a single argument to argv[1]. The child process executes the command with its argument. The parent outputs the time taken by the child process. Use the time() function (read its man page if you do not know how to use it).

    For example, if you name your program howlong, then

    howlong sleep 1

    executes sleep 1 in the child process and the time taken for execution is output by the parent process.
  4. Explain the use of "&" at the end of a Linux command using your knowledge of fork() and exec. What exactly is the difference between using an "&" and not using it?
  5. Given this program, draw the resulting process relationships, i.e., which process is the parent, which are the children, etc. Prove that you are correct by showing a "ps" command output and explaining the output.

REMEMBER THE ASSIGNMENT IS DUE ON 4 SEPTEMBER 2014