Menu

Class 10: Homework


You must print this sheet out and write/type answers on it!

  1. Suppose process 1010 is running and calls fork (successfully!). Modify the diagram below, which shows the state of the kernel prior to the fork, to show its state after the call to fork, labeled "Point A" in the code below. NOTE: in the diagram, a "?" simply refers to a location not shown in thediagram.
    int main()
    {
      int fd = -1;
      pid_t t = fork();
      ← Point A
      if (t == 0)
      {
        fd = open("tmp.txt",O_WRONLY|O_CREAT);
        dup2(fd,1);      
      }
      ← Point B
      return 0;
    }
    	    

  2. Continue on and show the stat at the point in the code labeled "Point B".
    int main()
    {
      int fd = -1;
      pid_t t = fork();
      ← Point A
      if (t == 0)
      {
        fd = open("tmp.txt",O_WRONLY|O_CREAT);
        dup2(fd,1);      
      }
      ← Point B
      return 0;
    }
    	    

  3. If we wanted the child process to send a single byte of data to the parent process, explain how it could be done. I.e. what appears after Point B in the code?