Repository navigation
pidof: match processes by executable and by rewritten titles - #818
jayhemnani9910 wants to merge 1 commit into
Conversation
pidof took argv[0] as the first space-separated word of the joined command line. Servers that rewrite their title, like "sshd: /usr/sbin/sshd -D [listener]", came out as "sshd:", so "pidof sshd" found nothing, while "pidof sshd:" matched. A process started with another argv[0] (exec -a) was not found by its program name either. Match like procps-ng: the base name of the whole argv[0], the base name of /proc/PID/exe (also cut to the 15 bytes the kernel keeps), or, when argv[0] has a space in it, the process name.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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 #818 +/- ##
==========================================
+ Coverage 19.20% 19.53% +0.33%
==========================================
Files 68 68
Lines 10156 10268 +112
Branches 546 556 +10
==========================================
+ Hits 1950 2006 +56
- 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:
|
pidoftakes argv[0] as the first space-separated word of the joined command line, and only compares that. Two common cases miss:sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups, which becomessshd:. Sopidof sshdfinds nothing andpidof sshd:matches. Any program with a title likename: worker processhas the same problem.exec -a, or a program that sets its own name) isn't found by its program name.Now it matches the way procps-ng's
pidofdoes:/proc/PID/cmdlinewithout joining the arguments/proc/PID/exe, also when cut to the 15 bytes the kernel keeps for the process nameThe
-xscript check reads its argument the same way. Nothing else changes.Testing:
test_process_with_another_argv0copies/bin/shunder its own name and runs it once with the titlepidoftitletest: worker processand once with argv[0]another-argv0.pidof pidoftitletesthas to find it andpidof pidoftitletest:must not. It fails on main. The spawn retries on ETXTBSY, since other tests fork while the copy can still be open for writing.cargo test: 225 passed (224 on main), clippy and rustfmt clean.pidoffrom procps-ng 4.0.4 (built from the release tarball, since Ubuntu'spidofis sysvinit's) on the same running system: 36 names over test processes (titles with spaces,exec -a, a 19-byte program name, a path with a space, a renamed perl$0, shell scripts with and without-x) and system daemons (sshd,systemd,init,cron,dbus-daemon,polkitd, ...). All match, as do-s,-o,-qand several names at once. The rest were a short-lived subshell inpidof bashand the-dalias, which this pidof adds on purpose.