This repository has been archived by the owner on May 4, 2018. It is now read-only.
Add Flag to Spawn Child Process with New Process Group ID but the Same Session ID #934
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.
I am working on a primitive shell in node that has full-fledged job-control. Proper job control requires being able to spawn child processes with the same session id, but in a new process group. Currently libuv only supports flagging a child for complete detachment via
UV_PROCESS_DETACHED
.A bit on TTYs and why this is necessary. I apologize if this is all familiar.
Background
Whenever you log into a shell, such as bash, there is always a controlling TTY for the session. That controlling TTY is just a file descriptor for a character device e.g.
/dev/console
. The reason you see the output from a command likels
is because after bash forks, it keeps STDOUT/STDERR attached to the controlling TTY before callingexec
onls
. Thus the TTY is being shared by almost every process that is a direct or indirect child of your login session.In order to calm the madness, the TTY drive has the concept of a foreground process group. Only processes in the foreground process group are allowed to read and write to the TTYs character device. If a background process tries to read or write to the TTY it will be sent
SIGTTIN
orSIGTTOUT
. TheSIGTTOUT
signal can be ignored, but ignoringSIGTTIN
will result in anEIO
read error.The foreground process group also lets the line-discipline decide which processes should be sent control signals like
SIGINT
whenever it processes a^C
character.Problem
The problem is that the system call (tcsetpgrp) for setting foreground process groups can only be done on process groups in the same session. Thus using
UV_PROCESS_DETACHED
will causetcsetpgrp
to error.