Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

feat: improvements to subprocess functionality #2047

Merged
merged 4 commits into from
Mar 3, 2025
Merged

Conversation

gau-nernst
Copy link
Contributor

Describe Your Changes

This PR was originally from #2010. I open this PR to merge the changes for subprocess functionality and keep #2010 smaller / more manageable. The improvements here will be used by my Python engine.

  • Use cpp::result (instead of -1) to explicitly signal error when spawning process. This also addresses the problem that pid_t on Windows is DWORD i.e. unsigned int, which may lead to unexpected behavior if we use -1
  • Add support for redirecting stdout and stderr when spawning subprocess
  • On Windows, use a Job object to terminate the process and its children. Otherwise, children processes are not terminated.
  • Create a ProcessInfo struct to clean up resources after process termination (right now only used by Windows to close handles)
  • Fix IsProcessAlive() on Unix. kill(pid, 0) will return 0 (success) if the process has terminated but not reaped (i.e. exit status is still stored in process table). Hence, using waitpid(pid, NULL, WNOHANG) is more reliable.

Fixes Issues

Self Checklist

  • Added relevant comments, esp in complex areas
  • Updated docs (for bug fixes / features)
  • Created issues for follow-up changes or refactoring needed

@gau-nernst gau-nernst self-assigned this Feb 28, 2025
@gau-nernst gau-nernst added this to Menlo Feb 28, 2025
@github-project-automation github-project-automation bot moved this to Investigating in Menlo Feb 28, 2025
@gau-nernst gau-nernst merged commit 0d744fc into dev Mar 3, 2025
8 checks passed
@gau-nernst gau-nernst deleted the thien/process branch March 3, 2025 14:43
@gau-nernst gau-nernst moved this from Investigating to Completed in Menlo Mar 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

idea: [subprocess] Redirect stdout and stderr of subprocess to file bug: Issues with subprocess management in Windows
2 participants