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 processes in the job 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, unless it is created with CREATE_BREAKAWAY_FROM_JOB. This means if we add ourselves to the job object we create then all processes remaining in the job will get torn down!
Modules§
- imp 🔒