-
-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for pid without polling using kevent on MacOS/BSD #1415
Comments
Code is more complex for a very small gain. Not sure it's worth it... |
On Windows one can also wait for a process by WaitForSingleObject and get its exit code by GetExitCodeProcess. Replacing polling may not have much benefit, but having exit code is useful. For example, one can monitor all processes and log their exit codes for debugging or auditing, or make a child process wait for its parent and log the code or restart it if it didn't exit normally. |
I see. What would the API look like then? |
To avoid breaking change and make it obvious that some OS may not support this, I'd like to add a separate function, like impl Process {
/// ### Implementation notes
/// Only Windows (and macOS) are supported.
///
/// On Windows, in addition to `PROCESS_QUERY_LIMITED_INFORMATION`, `PROCESS_QUERY_INFORMATION` access right is required.
pub fn wait_with_status(&self) -> Option<ExitStatus> {
todo!().map(std::process::ExitStatus::from_raw)
}
} |
Breaking change is fine considering there are already a few merged, so next release will be a major in any case. I also need to add a new |
On MacOS (and BSD), you can wait for a process to finish using kqueue/kevent (https://man.freebsd.org/cgi/man.cgi?query=kevent&manpath=FreeBSD+9.0-RELEASE) instead of polling waitpid. An old Apple technical note mentions this, which is how I originally found this. You can also get the exit status from the completed event this way.
Here's how I did it in my program (before realizing nix crate had event feature that let me not use unsafe):
Probably not really needed since polling works fine but it'd be nice to have.
The text was updated successfully, but these errors were encountered: