[-] Lab 6 - Task 2
by waldr - Sunday, 22 May 2016 17:03:35
Hey,
Shouldn't we follow these steps? (the changes are in italic):

  1. Create a pipe.
  2. Fork to a child process (child1).
  3. On the child1 process:
    1. Close the read-end of the pipe.
    2. Close the standard output.
    3. Duplicate the write-end of the pipe using dup (see man).
    4. Close the file descriptor that was duplicated.
    5. Execute "ls -l".
  4. On the parent process: Close the write end of the pipe.
  5. Fork again to a child process (child2).
  6. On the child2 process:
    1. Close the write-end of the pipe.
    2. Close the standard input.
    3. Duplicate the read-end of the pipe using dup.
    4. Close the file descriptor that was duplicated.
    5. Execute "tail -n 2".
  7. On the parent process: Close the read end of the pipe.
  8. Now wait for the child processes to terminate, in the same order of their execution.

Thank you!
Re: Lab 6 - Task 2
by llutan - Tuesday, 24 May 2016 15:28:05
Regarding 6.a, since the parent closes the write end at step 4, it can't be closed again in step 6.a.

Regarding 3.a, closing the read end won't cause any problems (and it can be argued that it's a cleaner way to do this), but in our case, keeping it open won't either (consider what exactly is the problem with leaving the write end open - think EOF).