Expand description
Job management (mostly for windows)
Most of the time when you’re running cargo you expect Ctrl-C to actually terminate the entire tree of processes in play, not just the one at the top (cargo). This currently works “by default” on Unix platforms because Ctrl-C actually sends a signal to the process group rather than the parent process, so everything will get torn down. On Windows, however, this does not happen and Ctrl-C just kills cargo.
To achieve the same semantics on Windows we use Job Objects to ensure that all processes die at the same time. Job objects have a mode of operation where when all handles to the object are closed it causes all child processes associated with the object to be terminated immediately. Conveniently whenever a process in the job object spawns a new process the child will be associated with the job object as well. This means if we add ourselves to the job object we create then everything will get torn down!