Skip to content

pgrep: compare --older with the process's age - #821

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:pgrep-older-uses-age
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:pgrep-older-uses-age

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

pgrep --older N (and pkill/pidwait, which share the matcher) should select processes that have been running for at least N seconds. It compared N with the process's start time, which /proc//stat gives in clock ticks since boot, so on any machine up for more than N/100 seconds every process matched:

$ sleep 100 & sleep 2.5
$ pgrep --older 5 -x sleep      # procps-ng 4.0.4: nothing; main: lists the 2.5 s old sleep

The matcher now reads the time since boot (/proc/uptime) and the clock tick rate (sysconf(_SC_CLK_TCK)) once, and keeps a process when now - start_time >= N * ticks. Without --older nothing changes.

Against procps-ng 4.0.4 with a 2.5 s old process: --older 0/1/2 match, --older 3/5/99999999 don't, on both. --older 60 -x systemd gives the same processes. A huge N saturates instead of overflowing.

Test test_older_compares_process_age: a just-spawned sleep is listed with --older 0 and not with --older 60 (fails on main). cargo test: 225 pass (224 on main), cargo clippy --all-targets -- -D warnings clean.

The start time in /proc/<pid>/stat counts clock ticks since boot, so
comparing it with the --older seconds matched nearly every process.
Compare the time since the process started instead.
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 37.50000% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.45%. Comparing base (67832aa) to head (f223b37).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/pgrep/src/process_matcher.rs 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #821      +/-   ##
==========================================
+ Coverage   19.20%   19.45%   +0.24%     
==========================================
  Files          68       68              
  Lines       10156    10257     +101     
  Branches      546      552       +6     
==========================================
+ Hits         1950     1995      +45     
- Misses       8206     8262      +56     
Flag Coverage Δ
macos_latest 6.75% <0.00%> (+<0.01%) ⬆️
ubuntu_latest 19.81% <38.70%> (+0.25%) ⬆️
windows_latest 0.02% <0.00%> (ø)

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.

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.

2 participants