How to count resource usage in linux

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 5

It will output something like this:

PID  	PPID 	CMD                      	%MEM 	%CPU
2591	2113 	/usr/lib/firefox/firefox    7.3 	43.5
2549   2520 	/usr/lib/virtualbox/Virtual 3.4  	8.2
2288       1 	/home/gacanepa/.dropbox-dis	1.4	0.3
1889   1543	c:\TeamViewer\TeamViewer.ex	1.0	0.2
2113	1801	/usr/bin/cinnamon		0.9	3.5

Sum can be count like this:

ps -eo pid,ppid,%mem,%cpu --sort=-%mem | head -n 5 | awk '{sum+=$4 ; print $0} END{print "sum=",sum}'

It will output:

PID  	PPID 	%MEM 	%CPU
2591	2113 	7.3 	43.5
2549   2520 	3.4  	8.2
2288       1 	1.4	0.3
1889   1543	1.0	0.2
2113	1801	0.9	3.5
sum= 55.7

https://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/

Total cpu info can be found as follows:

lscpu | egrep '^Thread|^Core|^Socket|^CPU\('

https://unix.stackexchange.com/questions/218074/how-to-know-number-of-cores-of-a-system-in-linux

LEAVE A COMMENT