Correct type returned by sysconf

At least on Linux, sysconf(_SC_OPEN_MAX) returns the correct value if
the setrlimit has been used to raise the current limit for file
descriptors.
Try not to leak PID slots

Set a flag when a child exits, then free the slot when all the fd's
associated with the child have been marked as closed. Presumably this
should prevent the situation where a signal has occurred but there is
pending data on an fd. In this case, the parent would previously discard
the data and free the slot immediately.