Repository navigation
pgrep: compare --older with the process's age - #821
jayhemnani9910 wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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:The matcher now reads the time since boot (
/proc/uptime) and the clock tick rate (sysconf(_SC_CLK_TCK)) once, and keeps a process whennow - start_time >= N * ticks. Without--oldernothing changes.Against procps-ng 4.0.4 with a 2.5 s old process:
--older 0/1/2match,--older 3/5/99999999don't, on both.--older 60 -x systemdgives the same processes. A huge N saturates instead of overflowing.Test
test_older_compares_process_age: a just-spawnedsleepis listed with--older 0and not with--older 60(fails on main).cargo test: 225 pass (224 on main),cargo clippy --all-targets -- -D warningsclean.