0
Linux Centos 6,64
I am using following command for displaying htop in the command column
htop -u command
How do I do for it to show only a specific command which i choose from those running commands list?
Thanks
0
Linux Centos 6,64
I am using following command for displaying htop in the command column
htop -u command
How do I do for it to show only a specific command which i choose from those running commands list?
Thanks
2
In htop -u
the parameter is a user name, not a command.
The only option to monitor a specific command is -p
, but this takes a PID, so the command name must be converted to a PID first, which pidof
will do.
If more than one instance of a command is running, pidof
returns a space-separated list of PIDs, but the -p
option takes a comma-separated list, so the pidof
output must be converted:
htop -p $(pidof command | sed 's/ /,/g')
This is best incorporated into a function or script, in which case the command will be:
htop -p $(pidof "$1" | sed 's/ /,/g')
Although I first think of sed
for batch editing, in this case the simpler tr
command could be used:
htop -p $(pidof "$1" | tr ' ' ',')
Note that GUI system monitors, such as qps
and ksysguard
, can filter the output and show specific commands directly (though the text-based filter may also pick up the command name if it happens to appear in the parameter list of another command).
Hello AFH, thanks for your reply. The commands you suggested came up with following message in here "Error: unknown flag: -p" . – Mike – 2018-03-09T22:45:43.390
You must have a different version of
htop
: mine is 2.0.1, as shown byhtop -v
. – AFH – 2018-03-09T22:56:05.540Hello, have updated it, its working now, thank you very much ! – Mike – 2018-03-09T23:23:20.510