Skip to content

process_matcher: Fix accidentally matching against pid#328

Merged
cakebaker merged 1 commit intouutils:mainfrom
dezgeg:pid_match_bugfix
Feb 19, 2025
Merged

process_matcher: Fix accidentally matching against pid#328
cakebaker merged 1 commit intouutils:mainfrom
dezgeg:pid_match_bugfix

Conversation

@dezgeg
Copy link
Contributor

@dezgeg dezgeg commented Feb 18, 2025

Currently pgrep/pkill without -x/-f flags is matching based on the first 15 characters of /proc//stat, which actually contains something like "1116878 (cat) R" thus matching the process id when it should just match on the name.

This has probably come from misunderstanding the comment from manpage:

The process name used for matching is limited to the 15 characters
present in the output of /proc/pid/stat.

... which doesn't mean pgrep/pkill is literally matching on 15 characters of /proc//stat but that the process name in that file is truncated to 15 characters.

Fixes #307

@sylvestre
Copy link
Contributor

would it be possible to add a test to make sure we don't regress? thanks

Currently pgrep/pkill without -x/-f flags is matching based on the first
15 characters of /proc/<pid>/stat, which actually contains something like
"1116878 (cat) R" thus matching the process id when it should just match
on the name.

This has probably come from misunderstanding the comment from manpage:

> The process name used for matching is limited to the 15 characters
> present in the output of /proc/pid/stat.

... which doesn't mean pgrep/pkill is literally matching on 15
characters of /proc/<pid>/stat but that the process name in that file is
truncated to 15 characters.

Fixes uutils#307
@dezgeg
Copy link
Contributor Author

dezgeg commented Feb 18, 2025

would it be possible to add a test to make sure we don't regress? thanks

Added

@cakebaker cakebaker merged commit b03e8ce into uutils:main Feb 19, 2025
14 checks passed
@codecov
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (b633a46) to head (43f7412).
Report is 9 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #328   +/-   ##
===========================
===========================

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

@cakebaker
Copy link
Contributor

Thanks!

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.

pkill: Some behavior seems doesn't match

3 participants