I am trying to use
ps -C chromi*
to see all chromium processes no success. How can I use regular expression in here?
CodePudding user response:
How to use "Regular Expression" in ps?
You cannot, ps
does not support regular expressions. The argument is parsed literally.
How to use "Regular Expression" in ps?
You can patch procps
ps
to support it, most probably (with yet another!) additional flag. The patch looks simple, basically another tree traversing parse_*
function that uses regex.h
instead of strncmp
.
I doubt such patch would make it upstream - it's typical to use other tools, most notably pgrep
or shell with a pipe and grep
, to filter process by command line name. ps
has to stay POSIX compatible, and has so many options already.
Note that regular expression is not "globbing". Consult man 7 glob
vs man 7 regex
. Regular expression chromi*
would match chrom
or chromiiiii
- chrom
followed by zero or more i
.
Note that unquoted arguments with "trigger" characters undergo filename expansion (ls 'chromi*'
vs ls chromi*
). This is different than passing the literal argument when there exist files that match the pattern. If the intention is to pass the pattern to the tool, quote the argument to prevent filename expansion.
CodePudding user response:
I think you are looking for pgrep
:
pgrep -f chromium
This will print pids only, no further information.
With the help of xargs
, this can be piped to ps again for detailed output:
pgrep -f chromium | xargs ps -o pid,cmd,user,etime -p