Correct solution with system call error checking.
Finished comments, though tests 11-13 are wrong on one process state