← All commands
THE COMMAND REFERENCE

top

Show the busiest processes and the load, updating as you watch.

Last updated

macOS / Apple

Implementation-level reference; examples are not certified for every installed version.

Overview

top shows a live table of the processes that use the most processor time or memory, with a summary of load and memory above it. It refreshes every few seconds until you press q. It is meant for a person at a terminal. For scripts, each version has a batch form that prints once and exits, which is what the examples use.

Background

Today the name covers top from procps-ng, the top that macOS ships and the top applet in BusyBox. They differ widely in their options: macOS uses -l for a number of samples, and procps and BusyBox use -b -n. The first example on this page needs a terminal and was reviewed only.

Examples

Run it at a terminal; keys such as q (quit) and k (kill) are shown in the top lines:

top

Common mistakes

top takes a few seconds to sample, so a script that calls it is slow. The first sample can show wrong values for the percentage of processor, because it is an average since the process began. Press q to quit; if the terminal is left in a strange state, run reset. Do not parse its screen output: ps -o gives columns that scripts can read.

Portability

The example that needs a terminal was reviewed only. The batch forms differ: macOS top -l 1, procps and BusyBox top -b -n 1. Their first line differs too, as the sections below show. The batch examples in the sections below were executed on macOS system tools, procps-ng and BusyBox 1.37.0.

About macOS top

This is the top in the system folders of macOS. It follows the BSD implementation.

Apple examples

Print one sample and stop with -l 1; the number of processes follows -n, and 0 prints only the summary. The first line starts with Processes:

top -l 1 -n 0 | head -n 1 | grep -c Processes

Apple notes

macOS top has -l for a number of samples, -o to sort and -n for the number of processes to list.

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.