0

How to write a shell script to filter out the %Mem consumption of some process like Mozilla Firefox and LibreOffice Writer. Both values need to sum up.

0

Use below command to find the same

ps axo %mem,command | egrep "Firefox | Writer" | awk 'BEGIN {sum=0} {sum =sum +$1}END {print sum}'
| improve this answer | |
  • I had try it but command not found, the full question is like : The ps command is able to show the total Memory resource consumption in terms of percentage (shown in %Mem column). Write a shell script to filter out the %Mem consumption of Morzilla Firefox and LibreOffice Writer. Both values need to sum up and output it to a file called morzilla.log. Your script must be able to let the user to determine the period (how frequent) of monitoring the %Mem reading. Moreover, if the user intends to record down the reading every 4 seconds, the command shall be: ./monitor.sh 4 – WHGG Nov 23 '17 at 19:32
  • Its working fine for me ps axo %mem,command | egrep “process1|process1” | awk 'BEGIN {sum=0} {sum =sum +$1}END {print sum}' As i checked in centos. kinldy confirm in which os you have checked – Praveen Kumar BS Nov 24 '17 at 1:48
  • using fedora with virtual box – WHGG Nov 26 '17 at 8:04
  • it works , answer is 4.1, how to make sure it is the correct answer? – WHGG Nov 26 '17 at 17:12
0

If you are not writing this in a script, I like htop http://hisham.hm/htop/ apt install htop

Otherwise use /proc/$PID/status

| improve this answer | |
  • need to write it in script haha – WHGG Nov 23 '17 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.