Lab 4: IPC

In this lab, you'll use labs to redirect a process's standard I/O and see how to use posix_spawn() instead of traditional UNIX process utilities. Section 3.3 of the book will be helpful.You should also consult the POSIX documentation as needed for the following functions:

  • strchr(), calloc(), free()
  • fork(), execlp(), pipe()
  • open(), close(), read(), write()
  • posix_spawn_file_actions_init(), posix_spawn_file_actions_addclose(), posix_spawn_file_actions_adddup2(), posix_spawn()

Preliminaries

Set up a bare repository on stu.cs.jmu.edu based on the instructions in the CS 361 Submission Procedures, using the name lab4-ipc.git.


Implementation Requirements: Pipes and Spawn

The goal for this lab is to get used to the basic functionality of pipes for standard I/O redirection. Both of these skills are required for the latter part of the project.

  1. Start at the top of pipe.c and build the implementation piece by piece. First, implement create_child() to create a child process, redirect its output to a pipe (provided as an argument), and execute a given program name. That is, create_child() mostly focuses on what the child needs to do after it is created. Note that the child must not return if exec() fails.
  2. Then move on to get_result() to implement the parent's portion of the work. That involves setting up the pipe and calling create_child(). After the child is created, make the parent wait on the child until it finishes executing and read the result. After completing this step and correcting the expected files, you should be passing all unit tests and the non-spawn() integration tests.
  3. Complete the implementation of spawn_cksum() in pipe.c so that it behaves the same as calling get_result(). Instead of using fork() and exec() to run the executable program, create the pipe and use posix_spawn(). See the slides for documentation on how to use functions for the posix_spawn_file_actions_t struct.


James Madison University logo


© 2011-2025 Michael S. Kirkpatrick.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.