I have to write a python script which has to give CPU usage for particular process.
Ex: Lets say i have a process ABC which is running continuously for 10 hours.(Process may have 'n' number of threads.)
So,
1st) My script should have to check the CPU usage and Memory consumption for process ABC, and also for threads of it after every 5 seconds.
2nd) Script has to take an average of CPU usage and memory consumption and it has to print final result.
i have tried using this command ,
top -bn1 | grep "Cpu(s)" | \
sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
awk '{print 100 - $1"%"}'
Can anyone help in find out?