Repository navigation
Add Background(): start a process that shares nothing with the caller - #10
Merged
Merged
Conversation
No window, none of the caller's handles or streams (so $(script), pipes and test harnesses are not held open), and cut loose from the terminal: its own process group on Windows (CreateProcess with bInheritHandles=FALSE, CREATE_NO_WINDOW), its own session on Linux (setsid), nohup on macOS. Returns the program's own pid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # src/CShell.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Background(program, args...)(onCShellandGlobals) for servers and daemons that should outlive the script, and bumps the version to 3.3.0.Why
Start()andRun()can't promise that the new process stays out of the caller's way:Process.Startpasses every handle the caller can share to the child. That includes the stdout pipe of whoever is capturing the script's output, so$(script), pipes and test harnesses wait until the child exits.Start()keeps its current behaviour, which is right for apps you open and leave.What it does
CreateProcesswithbInheritHandles=FALSE,CREATE_NO_WINDOWandCREATE_NEW_PROCESS_GROUP. The process gets a console no one can see, and programs it starts don't each open a window./bin/shpoints the program's input and output at/dev/null, then replaces itself withsetsidso the program leads its own session.setsidcommand, so it runs undernohup. It survives the terminal closing, but not a Ctrl+C sent while the script is still running. This is documented.CurrentFolder(orWorkingDirectory), takes environment variables, followsEcho, and throwsWin32Exceptionfor a program that can't be found.Background()section.Tests
Tests/BackgroundHostis a small helper program that records what it was started with.BackgroundTestschecks:WorkingDirectoryoption overrides that;bInheritHandlesto TRUE makes this test fail, so it does catch a leak;Results:
🤖 Generated with Claude Code