30 examples of the top command

Source: Internet
Author: User

The top command in Linux displays the processes that are running on the system. It is one of the most important tools for system administrators. is widely used to monitor the load on the server. In this article, we will explore the details of the top command. The top command is an interactive command. You can also run a lot of commands when you run top. We will also explore these commands.

(Note: The top commands for different distributions differ in a variety of details, and if not, read your help manuals and help in the commands.) )

1. Top command output

First, let's look at the output. The top command displays a lot of information about the system. We need to understand the meaning of the different parts of the output: the default runtime, the top command displays the following output:

The first few lines show a summary of the different system parameters, followed by the processes and their properties in the column.

1.1 System run time and average load:

The top of the top command displays output similar to the uptime command.

These fields display:

    • Current time
    • Time the system has been running
    • Number of currently logged-in users
    • The average load in the corresponding last 5, 10, and 15 minutes.

You can use the ' l ' command to toggle the display of uptime.

1.2 Tasks:

The second line shows a summary of the task or process. The process can be in a different state. This shows the total number of processes. In addition, there are the number of running, sleeping, stopping, zombie processes (zombies are the state of a process). The summary information of these processes can be toggled with ' t ' display.

1.3 CPU Status:

The next line shows the CPU status. This shows the percentage of CPU time in different modes. These different CPU times represent:

    • US, User: CPU time for running (non-prioritized) users process
    • Sy,system: CPU time for running kernel processes
    • Ni,niced: CPU time of the user process that has the adjusted priority run
    • Wa,io wait: CPU time to wait for IO to complete
    • Hi: CPU time to handle hardware interrupts
    • Si: CPU time to handle software interrupts
    • ST: CPU time this virtual machine was stolen by hypervisor

If you are currently in a VM under a hypervisor, the hypervisor is actually consuming a portion of the CPU processing time.

You can toggle the display using the ' t ' command.

1.4 Memory Usage:

The next two lines show memory usage, a bit like the ' free ' command. The first line is physical memory usage, and the second line is virtual memory usage (swap space).

The physical memory is displayed as follows: All available memory, used memory, free memory, buffered memory. Similarly: The swap section shows: all, used, idle, and buffered swap space.

The memory display can be toggled with the ' m ' command.

1.5 Fields/Columns:

Under the system properties and states that are listed horizontally, the process is displayed in columns. The different columns represent the different properties that are explained below.

By default, top displays these properties about the process:

Pid

Process ID, unique identifier of the process

USER

The actual user name of the process owner.

PR

The scheduling priority of the process. Some values of this field are ' RT '. This means that these processes run in a real-time state.

NI

The nice value (priority) of the process. The smaller the value means the higher the priority.

VIRT

The virtual memory used by the process.

Res

The size of the memory resident. Resident memory is the non-exchangeable physical memory size used by the task.

Shr

SHR is the shared memory used by the process.

S

This is the state of the process. It has the following different values:

    • D-Non-interruptible sleep state.
    • R – Running state
    • S-Sleep state
    • T-is tracked or stopped
    • Z – Zombie State

%cpu

The percentage of CPU time that was used by the task since the last time it was updated.

%MEM

Percentage of available physical memory used by the process.

time+

The total CPU time to be used until the task is started, exactly 1% seconds.

COMMAND

The command used to run the process.

There are also many outputs that are not displayed by default, and they can display page faults, valid group and group IDs, and other more information for a process.

2. Interactive commands

As we said before, top is an interactive command. We have encountered some commands in the previous section. Here we will explore more commands.

2.1 ' H ': Help

First, we can use ' h ' or '? ' Displays the Help menu for the interactive command.

2.2 ' <ENTER> ' or ' <SPACE> ': Refresh the display

The top command refreshes the display by default at a specific interval (3 seconds). To refresh manually, the user can enter a carriage return or a space.

2.3 ' A ': Toggle alternate display Mode

This command toggles between full screen and alternating mode. In alternating mode, 4 windows are displayed (focus on the different fields respectively):

    1. Def (default field group)
    2. Job (Task field group)
    3. Mem (Memory field group)
    4. USR (User field group)

The four groups of fields share a single, configurable overview area and its own configurable task area. Only one window in 4 Windows is the current window. The name of the current window appears at the top left. (Only the current window will accept your keyboard interaction command)

We can switch between 4 windows with ' A ' and ' W '. ' A ' moves to the next window, ' W ' to the previous window. With the ' G ' command you can enter a number to select the current window.

2.4 ' B ': Trigger bold display

Some important information is displayed in bold font. This command toggles the bold display.

2.5 ' d ' or ' s ': Sets the refresh interval for the display

When you press ' d ' or ' s ', you will be prompted to enter a value (in seconds) that will be set to the refresh interval. If you enter the 1,top here, it will be refreshed every second.

2.6 ' l ', ' t ', ' m ': Toggle load, task, memory information display

This toggles the average load on the top, the task/cpu status, and the memory information in the overview display accordingly.

2.7 ' F ': Field management

Use to select the fields you want to display. Marked with ' * ' is selected.

The upper and lower cursor keys navigate within the field, and the left cursor key allows you to select fields, enter or right cursor keys to confirm.

Press ' < ' to move the sorted field to the left, ' > ' to move to the right.

2.8 ' R ': reverse sort

Toggles the reverse/general sort.

2.9 ' C ': Trigger command

Toggles whether the full path and program name are displayed when the process starts.

2.10 ' I ': Idle task

Toggles the display of idle tasks.

2.11 ' V ': tree view

Toggles the tree view.

2.12 ' Z ': Change color

Press ' Z ' to show the user a screen that changes the output color of the top command. You can choose between 8 colors for 8 task areas.

Shown below is the top view of the color display in 4.

2.13 ' z ': Toggle color display

Toggles color, which turns the color display on or off.

2.14 ' x ' or ' Y '

Toggle Highlight Information: ' X ' will sort the word highlighting (vertical); ' Y ' will highlight the running process (rampage). Depending on your display settings, you may need to make the output color to see these highlights.

2.15 ' u ': Process for a specific user

Displays the process for a specific user. You will be prompted to enter your username. The blank will show all users.

2.16 ' n ' or ' # ': Number of tasks

Set the maximum number of tasks to display

2.17 ' K ': End Task

One of the most important commands in the top command. Used to send signals to a task (usually an end task).

2.18 ' R ': Re-set priority

Re-sets the scheduling priority for a task.

3. Command-Line Options

These command-line options are mostly the same as the commands discussed above. The output of top can be manipulated with commands, but you can also run top with parameters to set the effect you want.

3.1-b: Batch processing mode

The-B option starts the top command in batch mode. This is useful when you want to save the output in a file.

3.2-C: Command/program name Trigger

As the command discussed above, this option is displayed in the status displayed (whether full path is displayed) in the last remembered program/command.

3.3-d: Setting the delay interval

Sets the display interval for top (in seconds). Like what.

    1. $ top-d 1

The top will be started at a refresh interval of 1 seconds.

3.4-i: Toggle Show Idle Process

This option sets the last remembered opposite ' I ' State of the top command.

3.5-n: Set Number of iterations

With the-n option, you can set the number of times the top exits the previous iteration.

    1. $ top-n 3

Will exit 3 times after the output is refreshed.

3.6-P: monitoring a specific PID

You can monitor the specified PID with the-P option. A PID value of 0 will be used as the PID of the top command itself.

3.7-u or-u: Username or UID

You can use these options to browse the processes for a particular user. The user name or UID can be specified in the options. The-P,-U, and-u options are mutually exclusive and can only be used with one of these options. When you try to use these options together, you get an error:

    1. $ top-p 28453-u Raghu
    2. Top:conflicting Process Selections (u/p/u)

30 examples of the top command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.