[cs631apue] HW2

Jan Schaumann jschauma at stevens.edu
Tue Nov 2 22:40:59 EDT 2021


Hello,

I'll be sending out grades for HW2 momentarily.  A few
notes applicable to most of you:

The assignment referenced and pointed you to the
system(3) function:
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdlib/system.c?rev=HEAD&content-type=text/x-cvsweb-markup&only_with_tag=MAIN

If you haven't looked at that, you probably missed a
few aspects of the assignment and you could have saved
yourself quite some work by using a lot of that code,
I think.


Many of you called wait(3) in the parent _before_ you
began readin data from the pipe.  This has the
potential of causing a deadlock: if the child writes
more data than fits into the pipe, then the child
write(2) will block, and the child will not terminate;
the parent, wait(3)ing on the child will never get to
consume the data.

This can be addressed by using non-blocking I/O --
something we'll cover in a future lecture -- but more
trivially, it can be resolved by moving the wait(3)
until after reading the data.


Several of you read data into a temporary buffer, then
copied the data from that temporary buffer into the
buffers passed into your function.  While not a
problem, it's also not necessary: you can write the
data directly into the buffer that was passed to you.


The signal handlers you installed must be restored
before your function returns, as otherwise they remain
in place for the duration of the program that calls
your function.  This is an important consideration
when you write code that is not restricted to one
specific program, but functions as a general purpose
library function.

-Jan


More information about the cs631apue mailing list