Solved pkill kills processes by arguments

even when called without the -f switch. Same for pgrep. 'pkill firefox' kills all python processes that have firefoxin the argument list as part of a path. Why?

... an effect of python called by a shell script with arguments?
... correction: pgrep does not list it, but pkill kills it.

(Reinstalled from source minutes ago
FreeBSD 15.1-STABLE stable/15-n285467-3d961305e170 GENERIC amd64)
 
i can't replicate it
also pkill and pgrep are the same binary
FreeBSD instance-20260827-1504 15.1-RELEASE-p4 FreeBSD 15.1-RELEASE-p4 releng/15.1-n283627-db6066678b33 GENERIC arm64
 
It also 'works' for other arguments of that python command ... and for other running python processes, too. And shprocesses.
The args are not exactly handled the same in /usr/src/bin/pkill/pkill.c
 
$ ls -li /bin/pkill /bin/pgrep
120052 -r-xr-xr-x 2 root wheel 18080 Sep 29 01:59 /bin/pgrep
120052 -r-xr-xr-x 2 root wheel 18080 Sep 29 01:59 /bin/pkill
do you have a mismatched version between kernel and userland ?
 
What's going on here? /bin/pkill is different from /bin/pkill?
Code:
# /bin/pkill -I movi
# pkill -I movi
kill -15 96367]
kill 96367 python3.12? n
# which pkill
/bin/pkill
#  ls -li /bin/pkill /bin/pgrep
561684 -r-xr-xr-x  2 root wheel 17696  1 Okt. 14:41 /bin/pgrep*
561684 -r-xr-xr-x  2 root wheel 17696  1 Okt. 14:41 /bin/pkill*

... it only happens when called from bash, not sh!
 
even when called without the -f switch. Same for pgrep. 'pkill firefox' kills all python processes that have firefoxin the argument list as part of a path. Why?

IIRC pkill/pgrep works with extended regular expressions - you need to anchor the match if you want to avoid a sub-string match on arguments.
 
1790869087699.png


from https://wwwth.mpp.mpg.de/members/hahn/humour/FieldGuideToAdministrators.html
 
Related, in terms of determining what you are getting with a command in bash:

Checking builtin(1), sh doesn't have a builtin which:

Code:
  Command       Standalone    csh(1)    sh(1)
[..]
  which         Yes           Yes       No

Bash also doesn't have a builtin which, so it doesn't know about aliases:

Bash:
[FreeBSD ~]$ which pkill
/bin/pkill
[FreeBSD ~]$ alias pkill='pkill -f'
[FreeBSD ~]$ which pkill
/bin/pkill

(Spot-checking linux, the which command can get set to a function that feeds in some information from the environment, so it can detect aliases, but it looks like it relies on options which FreeBSD's which doesn't have.)

You can use command -V <cmd> (described in 'SHELL BUILTIN COMMANDS' in bash(1)) to get more useful information:

Bash:
[FreeBSD ~]$ which which
/usr/bin/which
[FreeBSD ~]$ command -V which
which is hashed (/usr/bin/which)
[FreeBSD ~]$ which pgrep
/bin/pgrep
[FreeBSD ~]$ alias pgrep='pgrep -f'
[FreeBSD ~]$ which pgrep
/bin/pgrep
[FreeBSD ~]$ command -V pgrep
pgrep is aliased to `pgrep -f'
 
Back
Top