Enhancing Skills

top: Display the full command line of each process

Command: top

The top command displays a real-time view of system processes and their resource usage. By default, it shows the command line of each process in a truncated form, but you can configure it to display the full command line.


When you run the top command without any arguments, it provides a real-time, interactive display of system processes. The output includes various details such as process ID (PID), user, CPU and memory usage, and more.

Sample Command and Output:

$ top
top - 08:45:22 up  5:12,  3 users,  load average: 0.23, 0.19, 0.18
Tasks: 220 total,   2 running, 218 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.4 us,  0.9 sy,  0.0 ni, 95.4 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8000000 total,  4500000 free,  2500000 used,  1050000 buff/cache
KiB Swap:  2000000 total,  2000000 free,        0 used.  5250000 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  1564 root      20   0  168048  26840  22040 S   5.0  0.3   0:00.67 top
  1203 user      20   0 1544828 276816  85300 S   3.3  3.4   1:01.76 firefox
  3221 user      20   0  737192 143636  27868 S   2.0  1.8   0:30.42 code
  3312 user      20   0  463836  58740  17436 S   1.0  0.7   0:05.31 gnome-shell

Description of Output Columns:

  • top - 08:45:22 up 5:12, 3 users, load average: 0.23, 0.19, 0.18: Shows the current time, system uptime, number of logged-in users, and load averages for the past 1, 5, and 15 minutes.
  • Tasks: 220 total, 2 running, 218 sleeping, 0 stopped, 0 zombie: Provides a summary of the total number of processes and their states.
  • %Cpu(s): 3.4 us, 0.9 sy, 0.0 ni, 95.4 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 st: Displays CPU usage statistics, including user space (us), system space (sy), idle time (id), and other metrics.
  • KiB Mem : 8000000 total, 4500000 free, 2500000 used, 1050000 buff/cache: Provides memory usage details, including total, free, used, and buffer/cache memory.
  • KiB Swap: 2000000 total, 2000000 free, 0 used. 5250000 avail Mem: Shows swap space usage, including total, free, and used swap space.
  • PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND: The header of the process list showing columns for Process ID (PID), user, priority (PR), nice value (NI), virtual memory (VIRT), resident memory (RES), shared memory (SHR), process state (S), CPU usage (%CPU), memory usage (%MEM), cumulative CPU time (TIME+), and command name.
  • 1564 root 20 0 168048 26840 22040 S 5.0 0.3 0:00.67 top: Example entry showing details for a specific process (in this case, top itself).

The display is interactive, allowing you to sort processes, filter them, and adjust the refresh rate.

Description:

  • Displays a list of processes with their CPU and memory usage, among other information. The command line may be truncated by default.
  • top -c: Displays the full command line of each process. Sample Command and Output:
  $ top -c

Description:

  • -c: Shows the full command line of each process, rather than truncating it.
  • top -d 10: Updates the display every 10 seconds. Sample Command and Output:
  $ top -d 10

Description:

  • -d: Sets the delay between screen updates. In this example, the display refreshes every 10 seconds.
  • top -p 1234: Displays only the process with PID 1234. Sample Command and Output:
  $ top -p 1234

Description:

  • -p: Shows information only for the specified process ID (PID). This example filters the display to only show the process with PID 1234.
  • top -n 1: Shows only one iteration and then exits. Sample Command and Output:
  $ top -n 1

Description:

  • -n: Specifies the number of iterations to run. In this example, top runs only once and then exits.

Note: top provides a dynamic and customizable view of processes. You can interact with it while it’s running, such as sorting by different columns and filtering processes.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.