0

top on Mac shows something like this on the top of the screen.

Processes: 1104 total, 187 running, 917 sleeping, 2761 threads 19:41:00

I don't want to run top interactively. Is there a way to run top noninteractive and just print this top line to the screen? Thanks.

user1424739
  • 11,937
  • 17
  • 63
  • 152
  • It sounds like your real question is "How can I get the number of processes running on my Linux system, broken down by running or sleeping?", correct? First thing I'd do is start looking at the `ps` command. – Andy Lester Apr 04 '19 at 00:54
  • No. Ps is not what I am looking for, as it prints too detailed info that I have to post-process. This can be very slow when the system is heavily loaded. It must be one command that directly print the summary. – user1424739 Apr 04 '19 at 01:22

2 Answers2

2

Try this:

$ top -l1 | head -n1

From the man:

-l samples Use logging mode and display samples samples, even if standard output is a terminal. 0 is treated as infinity. Rather than redisplaying, output is periodically printed in raw form. Note that the first sample displayed will have an invalid %CPU displayed for each process, as it is calculated using the delta between samples.

nbari
  • 25,603
  • 10
  • 76
  • 131
0

For example, like this:

top -b -n 1 |grep "Processes"

more information:

man top
Slawomir Dziuba
  • 1,265
  • 1
  • 6
  • 13