This is probably obvious to old school Unix hackers but won’t make ANY SENSE AT ALL until I realized that:
forkgets called without a block it spawns off a child process.
- Which means that the
ifstatement will get run twice, once on the parent process and the other on the child process.
if forkevaluates to true in the parent process since
forkreturns the process ID of the child procecess.
- In the child process
if forkgoes through the
elsestatement instead because
nilin a child process.
- The child process will be left hanging in a zombie state untill
Process.waitgets called in the parent process.
- You can’t write to a pipe until you close the read port and you can’t read from a pipe until you close the write port.