worldterminator
worldterminator

Reputation: 3066

Get topmost CPU usage PID and output it to a file

I want to count the CPU usage approximately but I don't want to use accton or any other software. Just only script. Can I use top to get the topmost CPU usage or memory usage's process name? When I use top -b I get a lot of unuseful information.

Upvotes: 2

Views: 593

Answers (1)

perreal
perreal

Reputation: 97968

For cpu usage:

ps -eo comm,%cpu --no-headers | sort -k2 -nr | head -1

For memory:

 ps -eo comm,%mem --no-headers | sort -k2 -nr | head -1

Upvotes: 1

Related Questions