There is a top
command to show running processes. I would like to print sorted list of unique values in field COMMAND
. There is my solution for this task
$ top -b -n 1 | tail -n+8 | awk '{print $12}' | cut -d'/' -f 1 | sort | uniq
However, this is too wordy command for so simple purpose. Is there a simpler solution for the task?
PS: I can use ps
instead of top
, but it returns too noisy format:chrome
vs /opt/google/chrome/chrome --type=renderer --enable- features=LinuxObsoleteSystemIsEndOfTheLine<LinuxObsoleteSystemIsEndOfTheLine --lang=en-US --force-
… this is just beginning of command.
Best Answer
I strongly recommend pouring over through the documentation for
ps
.These might be an interesting start:
or
You probably want the first one.
If you want absolutely fine-grained control, read the
Name
: line from/proc/nnnnnn/status
(or parse the string between the parens instat
) wherennnnn
represents all-numbers. For the full commandline, read/proc/nnnnnn/cmdline
, and translate the NUL bytes in the file to space characters.Note that
ps
on BSD (provided as part of that ecosystem) is a little different to Linux's version (supplied to Linux by the procps-ng project) and the two interpret their options a little differently. Worth noting if you're ever on *BSD.