Comp111: Operating Systems
Classroom Exercise 2
System Calls
Fall 2017

group member 1: ____________________________ login: ______________
group member 2: ____________________________ login: ______________
group member 3: ____________________________ login: ______________
group member 4: ____________________________ login: ______________
group member 5: ____________________________ login: ______________
group member 6: ____________________________ login: ______________
group member 7: ____________________________ login: ______________
group member 8: ____________________________ login: ______________

In class we have discussed many Linux system calls. Let's make sure we understand the important issues.

  1. Can a process's children see what it prints? Why or why not?






  2. Would a call that does a fork and exec as one thing be as useful? Why or why not?






  3. Why is it not necessarily a good idea to fork a program a large number of times to accomplish many separate tasks?






  4. Why would it be advantageous for an application program to avoid making system calls? What are the disadvantages of implementing something in the kernel rather than in user space?
  5. Consider the code:
     
    pid_t pid1, pid2; int status; 
    struct rusage usage; 
    if ((pid1=fork())) { 
        printf("I am parent %d; child is %d\n",getpid(),pid1); 
        pid2=wait3(&status, 0, &usage); 
        printf("exit code for %d is %d\n", pid2, status); 
    } else { 
        execl("/bin/cat", "/bin/cat", "/comp/111/news/0001.txt", NULL); 
        printf("we should never get here!\n"); 
    } 
    
    1. Explain exactly when the "if" statement is true.






    2. Why is the status an integer rather than something more complicated? What impact would there be for returning a more complicated status to the parent?






  6. (Advanced) I claim that in this particular case, whether the parent waits for the child is irrelevant and cannot create zombies. Why would that be? Under what precise conditions is it a bad idea for a parent to skip reaping of a child status?