Skip to content

handle kill -0 as signal shorthand and update PID handling - #18081

Merged
fdncred merged 2 commits into
nushell:mainfrom
fdncred:fix_kill_18080
May 4, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
fdncred:fix_kill_18080

Conversation

@fdncred

@fdncred fdncred commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes #18080. After this PR if you type kill -0 it'll now give an error similar to the one below.

User-facing changes (Release notes)

Updated kill signal shorthand handling

Allow kill -0 to show an error instead of killing nushell. Disallow commands like kill -9 pid because syntax should be kill -s 9 pid.

❯ kill -0
Error: nu::shell::incorrect_value

  × Incorrect value.
   ╭─[repl_entry #2:1:1]
 1 │ kill -0
   · ──┬─ ─┬
   ·   │   ╰── negative pid shorthand is not supported; use `kill -s 0 <pid>`
   ·   ╰── encountered here
   ╰────

Additional notes

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Apr 21, 2026
@Juhan280

Copy link
Copy Markdown
Contributor

Why are we treating -0 as a flag?

@fdncred

fdncred commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Why are we treating -0 as a flag?

I'm not really sure what you're asking. Is my description not good enough?

At some point we need to take this a step further and quit shelling out to kill processes. We also need to isolate better how Windows works vs how macos/linux works.

@Juhan280

Copy link
Copy Markdown
Contributor

Why are we treating -0 as a flag?

I'm not really sure what you're asking. Is my description not good enough?

At some point we need to take this a step further and quit shelling out to kill processes. We also need to isolate better how Windows works vs how macos/linux works.

What I meant is, that fact that nu was treating negative pid as signal number ws wrong in the first place. There is nowhere in the help page that suggest one can specify signal using -9. Nu treating that as SIGKILL is the bug.

@Juhan280

Copy link
Copy Markdown
Contributor

We should add cmd.arg("--") before line 55 here. So the pids are not treated a signals.

let mut cmd = CommandSys::new("kill");
if let Some(signal_value) = signal {
cmd.arg(format!("-{signal_value}"));
} else if force {
cmd.arg("-9");
}
cmd.args(pids.map(move |id| id.to_string()));
cmd

@fdncred

fdncred commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

If you want to rewrite this PR or another to fix this issue the way you think it should be done. Feel free. I'll close this one when that PR lands.

@Juhan280

Copy link
Copy Markdown
Contributor

@fdncred is there any reason we are not using uu-kill from uutils-coreutils

@fdncred

fdncred commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

@Juhan280

Copy link
Copy Markdown
Contributor

Ohh, I will see what other options we have. maybe will make a pr if i get something working

@fdncred

fdncred commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

I was looking around a bit this morning and found this. It doesn't look well supported but it does cover our platforms pretty good. https://github.com/harryplusplus/kill-tree/tree/main/crates/libs/kill_tree

@WindSoilder

Copy link
Copy Markdown
Contributor

I'm thinking that if we can set signature with allows_unknown_args: true attribute. Then we can get Argument::Unknown from ast::Call.

@Juhan280

Copy link
Copy Markdown
Contributor

Btw, in case you are not aware, negative pid for kill has special meaning.

From man 2 kill

If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals,
except for process 1 (init), but see below.

If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid.

@Juhan280

Copy link
Copy Markdown
Contributor

I'm thinking that if we can set signature with allows_unknown_args: true attribute. Then we can get Argument::Unknown from ast::Call.

Imo, we shouldn't treat negative pid as signals. And we don't according to the documentation. kill -9 pid is working because of a bug in our implementation which treats pid as signal.

@fdncred fdncred added notes:breaking-changes Noted in Breaking Changes section and removed notes:fixes Noted in "Bug fixes" section labels Apr 28, 2026
@fdncred

fdncred commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

I've updated the PR to disallow things like kill -0 or kill -9 pid in favor of kill -s 0 pid or kill -s 9 pid.

}
}

fn inferred_signal_number(raw: &[u8], pid: i64) -> Option<u64> {

@WindSoilder WindSoilder May 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is just checking raw[0] == b'-' enough? I guess raw itself is always a number.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think raw[0] is too brittle. I changed it to a safe parse of the raw token (optional '-' + digits), so kill -0 style shorthand is handled correctly without direct indexing assumptions.

@fdncred
fdncred merged commit b9d3a27 into nushell:main May 4, 2026
17 checks passed
@fdncred
fdncred deleted the fix_kill_18080 branch May 4, 2026 14:35
@github-actions github-actions Bot added this to the v0.113.0 milestone May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kill -0 behaves oddly

3 participants