Fix bugs in master

Ping @msmith-techempower and @aschneider-techempower for a code review before these changes are merged. I updated your port closing function quite a bit and fixed bugs that were preventing master from running properly. If this looks good it's ready to merge, but given how close you are to R10 I want someone to eyeball it before it hits master
Question: Do we need to do this *before* we kill the master? I'm not sure off the top of my head what happens to the child's PPID when the master is killed - is it just preserved, or does it reset to some other value?