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.
- Start at the top of
pipe.c
and build the implementation piece by piece. First, implementcreate_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 ifexec()
fails. - Then move on to
get_result()
to implement the parent's portion of the work. That involves setting up the pipe and callingcreate_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. - Complete the implementation of
spawn_cksum()
inpipe.c
so that it behaves the same as callingget_result()
. Instead of usingfork()
andexec()
to run the executable program, create the pipe and useposix_spawn()
. See the slides for documentation on how to use functions for theposix_spawn_file_actions_t
struct.