Skip to content

pidof: accept %PPID in -o - #820

Merged
sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:pidof-omit-ppid
Oct 29, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:pidof-omit-ppid

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

procps-ng's pidof documents a special value for -o: "The special pid %PPID can be used to name the parent process of the pidof program, in other words the calling shell or shell script." Init scripts and cron jobs use it to check whether another copy of themselves is running:

if pidof -o %PPID -x myjob.sh >/dev/null; then exit 0; fi

uutils pidof rejects it:

$ pidof -o %PPID -x myjob.sh
error: invalid value '%PPID' for '--omit-pid <PID>': invalid digit found in string

so the check always takes the "not running" branch after printing the error.

-o now goes through parse_omit_pid, which maps %PPID to std::os::unix::process::parent_id() and parses anything else as before (comma lists still work through value_delimiter).

Test test_omit_pid_ppid: pidof's parent is the test process, so pidof -o %PPID <test binary> must not list the test's PID (fails on main). cargo test: 225 pass (224 on main), cargo clippy --all-targets -- -D warnings clean. With a script run twice, the second copy's pidof -o %PPID -x lists only the first copy.

procps-ng pidof takes the special value %PPID for the parent of pidof,
so a script can check whether another copy of it is running with
'pidof -o %PPID -x name'. It was rejected as an invalid PID.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.51%. Comparing base (67832aa) to head (4f1424e).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/pidof/src/pidof.rs 0.00% 7 Missing ⚠️
tests/by-util/test_pidof.rs 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #820      +/-   ##
==========================================
+ Coverage   19.20%   19.51%   +0.30%     
==========================================
  Files          68       68              
  Lines       10156    10251      +95     
  Branches      546      553       +7     
==========================================
+ Hits         1950     2000      +50     
- Misses       8206     8251      +45     
Flag Coverage Δ
macos_latest 6.74% <0.00%> (-0.01%) ⬇️
ubuntu_latest 19.87% <68.00%> (+0.31%) ⬆️
windows_latest 0.02% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/by-util/test_pidof.rs Outdated
#[cfg(target_os = "linux")]
fn test_omit_pid_ppid() {
// pidof runs as a child of this test, so %PPID names this process.
let argv0 = std::env::args().next().unwrap();

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.

std::env::current_exe() would be simpler, no?

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.

Done in 4f1424e.

new_ucmd!()
.arg(&our_name)
.succeeds()
.stdout_contains(&our_pid);

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.

could you please also cover it in a list, like -o 1,%PPID?

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.

Added in 4f1424e: the test now checks both -o %PPID and -o 1,%PPID.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 06:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre
sylvestre merged commit d054699 into uutils:main Oct 29, 2026
18 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

3 participants