2

I am familiar with pidstat command that gives separate user and system CPU per process on Linux:

$ sudo pidstat -p 3162
Linux 4.18.0-13-generic (ubi)   26.12.2018  _x86_64_    (1 CPU)

11:26:13      UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
11:26:13     1000      3162    0.24    0.04    0.00    0.12    0.28     0  emacs

How can I accomplish the same on Mac OSX?

top on OSX gives these values but only on the machine level and not per process. For processes, it seems to give only total CPU used

Load Avg: 3.26, 3.02, 3.01  CPU usage: 3.13% user, 5.69% sys, 91.16% idle  SharedLibs: 169M resident, 44M data, 11M

PID    COMMAND      %CPU TIME     #TH   #WQ  #PORT MEM    PURG   CMPRS  PGRP  PPID  STATE    BOOSTS
97229  powerlogd    0.0  00:00.45 2     1    51    1160K  16K    1744K  97229 1     sleeping *1[1]

Per process, it shows only the total cpu percentage and not the user and system split. How do I get both user and system time?

  • you already have the answer the % split CPU is in coulomb 15 &16. So you have the Total and the split – Ruskes Dec 26 '18 at 1:25
1

Not sure the information you are looking for is accessible so easily. You could try ps

$ ps -p 407 -o pid,time,utime,etime,comm
  PID      TIME     UTIME     ELAPSED COMM
  407   2:08.23   1:46.36 11-17:10:27 /Applications/Aquamacs.app/Contents/MacOS/Aquamacs

and calculate the system time (TIME - UTIME) and the percentages. This is just the total since the process started though, not an ongoing sampling.

-1

You were close with Top command,

now try Top -A

and it will show you this per Process (PID)

enter image description here

or try this top -F -R -o cpu

All the possible Top command options

enter image description here

While Top is running press o (and/or Capital O) then use any of the listed options with it to modify what and how is it displayed in real time.

  • -A gives me an invalid syntax on HighSierra. top still displays the total cpu per process and not the user and system separately unless I missed something here. – Neo Dec 25 '18 at 19:34
  • I just tried the top -a on High Sierran and it does work – Ruskes Dec 25 '18 at 19:59
  • It shows CPU usage by user – Ruskes Dec 25 '18 at 21:12
  • May I wasn't very clear, top shows the process total cpu time and not the split. I need both user and system time. Updated the question too – Neo Dec 25 '18 at 23:15
  • OK, Total CPU is in 3d coulomb, the split is %CPU_me and %CPU_others in coulomb 15 &16 – Ruskes Dec 26 '18 at 1:22

You must log in to answer this question.

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