1

I have found that using activity monitor I get all the information I need. I now just need a way to access this information via preferably Python or even Bash and Apple Script. I just need to get the information at regular intervals and put it in a log file while my program is running.

1

The terminal command top will give you a list of running processes biggest ones first. Do man top and you will have a complete explanation of the syntax for your version.

Also of interest might be ps, especially if used in scripts. Run man ps for the details.

So, just to add this will give the initial information without any processes shown:

top -o cpu -O +rsize -s 5 -n 0

Based on the example shown in the man page for top. And this is what it looks like : enter image description here

  • Thanks @patrix I should have respected the formatting... And I will be looking at the ps command. – Solar Mike Jun 21 '17 at 6:25
  • thank you! I had another doubt. Is there any way to get only the total cpu usage and memory usage not related to any specific process. Basically, the first dew lines when top is given. I tried to grep, but I can't grep those lines. – ShdwKnght333 Jun 21 '17 at 6:52
  • top -o <key> , the definition of key is given in the man page, for the cpu use it is <cpu>. – Solar Mike Jun 21 '17 at 7:00
  • top -o sorts the list based on the key. What I want are the total CPU and memory usage. Not for a single application – ShdwKnght333 Jun 21 '17 at 9:16
  • The man page gives the example top -o cpu -O +rsize -s 5 -n 20, which if you change -n 20 to -n 0 will not show any processes but just the initial information : processes load average ... – Solar Mike Jun 21 '17 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .