How to get a list of process ids of long command names, not command line parameters?
2
votes
1
answer
1460
views
Since there's a 15-character limit on the length of process names in pgrep, I've been using
pgrep -f
to give me a list of process id's of running commands with longer names. However, it includes the full command line parameters, and this gives wrong results.
For example: suppose my_long_script_name.sh
is running while I vi my_long_script_name.sh
(ignore editing a running program for the moment).
If I run pgrep -f my_long_script_name.sh
, it returns the process id of both my_long_script_name.sh
and vi my_long_script_name.sh
.
How can I get a list of process id's (that I can feed to kill in a list, the same way pgrep -d ' '
makes them) that are based only on process names not parameter lists?
I'm running Buster but see the same problem in earlier OS's such as Wheezy. As requested, if I run sed -n l "/proc/$pid/comm"
, where $pid
is $BASHPID
of my terminal session, I get bash$
. If I run sed -n l "/proc/$pid/cmdline"
, I get -bash\000$
. That's a lower case L, not a one, after -n
. If I run cat -vte
, it hangs.
Asked by NewtownGuy
(41 rep)
Nov 21, 2020, 01:06 PM
Last activity: Mar 20, 2024, 07:16 PM
Last activity: Mar 20, 2024, 07:16 PM