Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Just what I was looking for' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Just what I was looking for
Authored by: VRic on Nov 19, '04 05:16:41PM

Great ! I was precisely looking for a workaround for top -l returning 0% CPU on 1st pass this morning!

I would have liked to get the full 2nd pass of top -l2 including all processes, but I don't know how.

Maybe one could count the number of lines, divide by 2, then return the second half of the output, which is the full second iteration of top -l2. Does anyone know how to do this?

In the meantime, here's what I did using only processes with more than 0%CPU.

To extract several columns from top's output, I made a template where I numbered the character positions of each column. Those who want custom output may find this useful:

(the first line shows column boundaries marked with the | character, eg PID is characters 1 to 5, process name is 6 to 16 etc.)

|1 5|        16|    24|      32| 36|   42|                  63|    70|    77|
  PID COMMAND      %CPU   TIME   #TH #PRTS #MREGS RPRVT  RSHRD  RSIZE  VSIZE
16786 top          2.5%  0:00.52   1    19     0     0K-    0K-  736K+ 27.1M+
15899 X Resource   0.9%  1:17.68   1    76     0     0K-    0K- 4.71M   206M 
10790 iCab         5.7% 72:27.70   8   207     0     0K-    0K- 97.5M-  381M 
  913 BitTorrent   0.3%  3:26:26   3    96     0     0K-    0K- 11.2M   235M 
  732 VLC          1.5% 95:52.83   7   193     0     0K-    0K- 29.9M-  433M 
  431 EyeTV Help   0.9%  2:19.16   1    74     0     0K-    0K-  760K   191M 
  428 Butler       0.3%  5:07.16   3   116     0     0K-    0K- 5.34M   263M 
  399 Finder       0.9% 43:49.23   4   961     0     0K-    0K- 39.9M   506M 
  210 WindowServ   7.3%  3:05:44   2   553     0     0K-    0K-  108M+  365M+
    0 kernel_tas   4.1%  1:42:41  35     2     0     0K-    0K  77.9M+  756M 

Here's an example to get the first 3 colmuns (notice that I don't grep just '0.0%' like the original hint, because this may also match 10.0%, 20.0%, etc.):

top -FR -l2  | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24

16589 top          2.3% 
15899 X Resource   1.3% 
11578 Carracho 1   0.3% 
10790 iCab         8.9% 
  913 BitTorrent   0.3% 
  732 VLC          0.3% 
  399 Finder       0.3% 
  397 Dock         0.3% 
  210 WindowServ   3.7% 
    0 kernel_tas   2.0% 

And here's what I use to show PID, name, CPU, threads, parts and memory usage in GeekTool (ranges are separated by commas):

top -FR -l2 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24,33-42,64-77

17249 top          2.4%    1    19  740K+ 27.1M+
16332 Terminal     0.4%    4    67 17.0M   222M 
15899 X Resource   0.8%    1    76 4.71M   206M 
11578 Carracho 1   0.4%    6   214 11.8M   297M 
10790 iCab         9.0%    8   207 93.7M-  381M 
  913 BitTorrent   0.8%    3    96 10.9M   235M 
  732 VLC          1.6%    7   193 28.6M   433M 
  437 System Eve   0.4%    1    72 1.74M   225M 
  432 ContourShu   0.4%    1    68  840K   200M 
  210 WindowServ   2.8%    2   564  103M+  363M+
    0 kernel_tas   1.6%   35     2 78.4M+  756M 


[ Reply to This | # ]
Just what I was looking for
Authored by: Dale Mox on May 11, '05 12:25:36AM

sweet. Thanks, Dale



[ Reply to This | # ]