feat: add ProcessSignaler to expose child process PIDs#160
feat: add ProcessSignaler to expose child process PIDs#160wolfv wants to merge 4 commits intodenoland:mainfrom
Conversation
I'm a little confused about this PR. Is this a replacement for |
src/shell/types.rs
Outdated
| /// Returns the PID of the current foreground child process, if any. | ||
| /// | ||
| /// Returns `None` if no child process is currently running. | ||
| pub fn current_pid(&self) -> Option<u32> { |
There was a problem hiding this comment.
There could be multiple child processes running at the same time:
deno eval 'console.log(1)' ; deno eval 'console.log(2)' &It seems this would only hold one of them?
|
Hey @dsherret to be completely transparent the changes here were written by Claude :) I didn't expect you to already take a look tbh. I am trying to fix an issue in Pixi where a user has issues to programmatically send CTRL+C to the process. ProcessSignaler is complementary to KillSignal, not a replacement.
The Problem: When you run pixi run python script.py in a terminal and press CTRL+C: The terminal sends SIGINT to the entire foreground process group
The challenge is: pixi needs to forward signals sent via kill, but should avoid double-forwarding when CTRL+C already delivered the signal to the child.
By default, child processes inherit the parent's process group. But processes can call setpgid() or setsid() to create a new process group. This happens with:
|
|
Here is an explanation in How are you solving this in |
|
Thanks! It seems a bit complicated to introduce a separate concept for this. Is there a way we could build this into KillSignal instead? For example, a way to say "send this signal only if a different process group". |
src/shell/types.rs
Outdated
| /// if child_pgid != our_pgid { | ||
| /// // Child in different process group, forward signal | ||
| /// kill_signal.send(SignalKind::SIGINT); | ||
| /// } |
There was a problem hiding this comment.
I don't think this would work because there could be multiple child processes running in different groups?
|
I still need to test in pixi whether this fixes our CTRL+C / kill signal issues. Marked the PR as draft. |
Add ProcessSignaler type to track spawned child process PIDs, enabling
proper signal forwarding by allowing callers to check process groups
before forwarding signals.