Linux top Command: Monitor Processes and CPU Usage in Real Time
The top command in Linux is an interesting way to view running processes in Linux, with real-time updates and sorted by the process that uses the most CPU, at the TOP of the screen.
This feature is useful for monitoring how one or more processes behave in the system.
The most commonly used options are:
- -b: Run in batch mode or batch file. It is used to redirect the command output to another process or to a file;
- -d n: Sets the screen update interval to n seconds. The default is five seconds;
- -n num: Shows the number of times on screen the updates of running processes and then terminates. Useful to use with the –b option;
- -q: Run with real-time updates. This option should be used with caution, as it can consume a large amount of CPU;
- -u: Monitor the running processes of a specific user;
- -p: Monitor a specific process identified by its PID. More than one process can be defined with this option.
The top command can also support some commands that change its behavior during execution. They are:
- Z: Changes the color scheme of top. For this option to be active, the terminal must support ANSI;
- F: Adds columns with more process monitoring options;
- u: Shows the processes of a specific user;
- k: Terminates (kill) a specific process;
- r: Changes the execution priority of the process (renice);
- R: Changes the order of processes according to CPU usage;
- q: Exits the interactive mode of top.
Top Command |
The top command on the first line provides the CPU load average, corresponding to 1 minute, 5 minutes and 15 minutes, the same as the "uptime" command. The higher the numbers, the more overloaded the system will be.
It is common for the system to experience high rates in the 1 minute average. But a constantly high average rate in the 15 minute indicator is a sign that the CPU is poorly sized.
On the second line there is the total number of processes, quantity in running state (running - which corresponds to the number of CPUs and cores), sleeping (which are on disk), stopped (stop) and zombie processes (child processes that stopped executing, but the parent process was not notified).
On the third line top shows the total amount of memory, free memory, used and in buffer/cache.
On the fourth line it shows Swap usage.
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.
Top Command