Hello All,
I am preparing a script to capture the processes consuming more CPU.
So is there any way that i can sort & redirect to file only those processes consuming more than 5.0 % using ps command itself.
Regards
Ankit
Hello All,
I am preparing a script to capture the processes consuming more CPU.
So is there any way that i can sort & redirect to file only those processes consuming more than 5.0 % using ps command itself.
Regards
Ankit
You can use this command:
ps --no-headers -eo "%p %C %U %c %a" | sort -r -n -k 2 | awk '{if ($2 > 5.0) {print $0}}' > output-file
This command outputs the PID, CPU usage, user owning the process, process name and parameters to the output-file.
If you want to change the CPU usage maximum value, change it in the awk body ($2 > 5.0).
Thanks for your inputs it helped me a lot,Can you please let me one more thing, how can i sort it based on memory utilization.
Try this
s --no-headers uax|sort -nrk6|head
The output contains below columns, RSS is the one you should target for memory utilization.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND