microsoft / microsoft/terminal
Job control and the Console API
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
The Console API is presently lacking any notion of the foreground process/process group; that is, there is no equivalent to the UNIX tcsetpgrp() call, and indeed the API documentation notes that in the presence of multiple processes there is no guarantee which process will receive input read from the console.
This is really quite a serious bug — it prevents the use of any kind of job control from the shell, because the shell has no way to cause a process to stop if it tries to read from the attached console. Yes, it's possible that a shell could create pseudo consoles for every subprocess and attempt to manage this itself, but that doesn't work if the subprocesses themselves spawn subprocesses.
Please take a look at https://ftp.gnu.org/old-gnu/Manuals/glibc/html_node/Access-to-the-Terminal.html#Access%20to%20the%20Terminal which describes the UNIX behaviour; you really want to make sure that it's possible to do similar things in the Windows API. In particular, it must be possible to send a console control message to a process if it tries to read from a console for which it is not the foreground process or in the foreground process group; the default behaviour for the message, if unhandled, should be to suspend the process. It must also be possible, optionally, depending on the console configuration, to cause output to behave the same way.
I'd suggest adding something like
BOOL ConsoleSetForegroundProcessGroup(HANDLE hConsole, HANDLE hProcessGroup);
HANDLE ConsoleGetForegroundProcessGroup(HANDLE hConsole);
Then I'd probably add an extra console mode flag to control the suspension of processes on output, maybe ENABLE_SUSPEND_ON_OUTPUT; you could also add ENABLE_SUSPEND_ON_INPUT and leave that off by default to maintain the present behaviour.
Finally, the console control events CTRL_SUSPEND_FOR_INPUT and CTRL_SUSPEND_FOR_OUTPUT need adding. It would also be a good idea to add, while you're about it, CTRL_SUSPEND, the default behaviour of which should be to suspend the process unless it's handled.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Console API documentation and the linked GNU terminal job-control description, then compare the proposed foreground process-group, suspension-mode, and control-event behavior with the current Windows console model. Done would require a settled design and implementation scope for these APIs and events; the issue does not name source files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100