Close all unneeded file descriptors before exec.
Make the new terminal a controlling one.
Merge pull request #291 from phantom10111/master

Exec procedure improvements