Skip to content

kill: implementation for Windows - #13604

Open
nikolalukovic wants to merge 4 commits into
uutils:mainfrom
nikolalukovic:feature/kill-windows
Open

kill: implementation for Windows#13604
nikolalukovic wants to merge 4 commits into
uutils:mainfrom
nikolalukovic:feature/kill-windows

Conversation

@nikolalukovic

Copy link
Copy Markdown
Contributor

Implement kill util for Windows since #13363 added most of plumbing needed.

Comment thread src/uu/kill/src/platform/windows.rs Outdated
@nikolalukovic
nikolalukovic requested a review from sylvestre July 27, 2026 14:29
@codspeed-hq

codspeed-hq Bot commented Jul 27, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.47%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 16 regressed benchmarks
✅ 328 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation hostname_ip_lookup[100000] 109.2 µs 119.8 µs -8.81%
Memory factor_multiple_u64s[2] 54.1 KB 57.6 KB -6.13%
Memory hostname_basic 56.3 KB 59.8 KB -5.9%
Memory seq_custom_separator 58.4 KB 61.9 KB -5.7%
Memory wc_lines_extreme_line_lengths[(100000, 200)] 65.1 KB 68.6 KB -5.14%
Memory nl_many_lines[100000] 66.2 KB 69.7 KB -5.06%
Memory unexpand_many_lines[100000] 67 KB 70.5 KB -5.01%
Memory expand_custom_tabstops[50000] 67 KB 70.5 KB -5%
Memory cut_fields_newline_delim 69.3 KB 72.8 KB -4.85%
Memory fold_custom_width[50000] 76.1 KB 79.6 KB -4.43%
Memory split_numeric_suffix 80.5 KB 84 KB -4.2%
Memory df_deep_directory 80.7 KB 84.3 KB -4.19%
Memory join_custom_separator 86 KB 89.5 KB -3.94%
Memory cksum_multiple_files 91.2 KB 94.7 KB -3.73%
Memory rm_recursive_tree 98 KB 101.5 KB -3.48%
Simulation single_date_now 83.8 µs 86.6 µs -3.22%
Simulation wc_bytes_synthetic[1] 83.9 µs 81.2 µs +3.25%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing nikolalukovic:feature/kill-windows (9dcb1d0) with main (41059cf)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)

Comment thread src/uu/kill/locales/en-US.ftl Outdated
@nikolalukovic
nikolalukovic requested a review from oech3 July 28, 2026 12:06
}

/// Deliver `signal` (POSIX numbering) to the arbitrary process `pid`,
/// emulating `kill(2)` for `pid > 0`. `SeDebugPrivilege` is never enabled.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is SeDebugPrivilege never enabled?

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.

it would go against the goals of the project and POSIX, self-escalation is strictly forbidden and considering how the privilege model is wildly different between Windows and Unix this felt, to me, like going with the best behaviour match. we could go with a separate windows only flag to emulate taskkill /F but that feels like shifting away from the core goals of the project too much

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not entirely sure I understand what you mean. Can enabling rights you already have access to really be considered self-escalation? No process on Windows just has SeDebugPrivilege automatically.

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.

oof I assumed this wasn't done but I just saw Cygwin does actually use sedebugprivilege in the force kill path, I completely misunderstood how it works. is it okay if we do the same here or should we just try and do it all the time without -f?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd be fine trying to enable it unconditionally. We could always fall back if it was not allowed!

Comment thread src/uucore/src/lib/features/process/windows.rs Outdated
Comment thread src/uucore/src/lib/features/process/windows.rs Outdated
Comment on lines +27 to +29
_ => Err(unsupported(translate!(
"kill-error-process-groups-unsupported"
))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not use TerminateJobObject here?

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.

how do we get the handle?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's no direct public Win32 or NT API for that. So, we got to get creative, and creative is unfortunately a bit involved. If you're using AI to code this, I assume it won't trouble you too much. Otherwise, let's consider this a TODO. The idea would be to iterate through all processes using NT APIs and filter down to the current process and get its Job ID. Then get all handles with SystemExtendedHandleInformation and get the matching Job handle and kill it. Something like that - it's probably quite a bit of code. (More than I would've assumed intuitively. 🙁)

Comment on lines +6 to +7
and STOP are not supported. Permissions come from your current token: kill
never enables SeDebugPrivilege, so an elevated kill may report 'Permission

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(Would you mind explaining in the PR body why not use SeDebugPrivilege?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm sorry, I missed the earlier comments as they were at the top level rather than in a file :)

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.

ye, I'm being educated left and right on this PR :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants