in reply to capturing exit status of a process

You actually want to examine the return value of the close() which has the exit code of the child program (or rather the return value of wait(3) but in this case it is the same.)

/J\