C programming tools
C programming tools (make, gdb, valgrind, git), signals and signal
handlers, man and appropos: see the
week 1 lab page
for links to
resources and examples.
Starting with lab 2, you will pick a partner with whom you will work
on all remaining lab assignments in this class.
It is advantageous to pick a partner who is in your same lab section, but
you are not required to do so.
I need to know your partner before 5pm on Friday so that I can set up
the lab 2 starting point for specific partner groups.
By no later than Friday at 5pm every student
in class (i.e. both you AND your partner) should email me the following
- Do you have a lab partner? YES or NO
- If YES, what are your and your partner's names and user names
I will pair up people who do not have partners. If you would would like
my help in finding a lab partner, send me email and I'll let you know about
other singles as I hear from them.
Pipes and I/O redirection
Copy over some code into your cs45/weeklylabs/02 directory:
cp ~newhall/public/cs45/week02/* .
Let's look at the example code in pipe_example.c
stolen from the pipe man page), and then run it to see what it is doing.
Can you answer these questions:
- How is the pipe set up (and who sets it up, when and how)?
- How does the child know when the parent is no longer going to
send it anything to read from the pipe (and what triggers the child
Next, try comment out this call to close in the parent code, rebuild and
close(pipefd); // this will cause reader to see EOF on read
You can attach gdb to the child process and see where it is:
gdb prog (child's pid)
What is happening with the child? and why?
pkill -9 prog # will kill both the parent and the child