Bash shell commands and monitoring that little Thing (ii)

Source: Internet
Author: User

Top of the Bash shell Command and monitor

  The last time we talked about the PS command, although the PS command is useful in collecting process information running on the system, but there are shortcomings, PS command can only display information at a specific point in time, if you want to observe the trend of the process of swapping out memory frequently, it is inconvenient to use PS command.

and the top command just applies to this scenario. The top command, similar to the PS command, displays information about the process, but it is displayed in real time. is the top command output:

1Top- -: About: -Up -Days at:Panax Notoginseng,3Users, load average:0.00,0.00,0.002Tasks:389Total1Running388Sleeping,0Stopped0Zombie3Cpu (s):1.4%us,0.5%sy,0.0%ni,98.0%ID,0.0%wa,0.0%hi,0.1%si,0.0%St4mem:3924432k Total, 3744996k used, 179436k Free, 144112k buffers5swap:2097144k Total, 1834356k used, 262788k Free, 396948k Cached
PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
11629 Root 0 15304 1484 952 R 1.6 0.0 0:04.29 Top

  The first part of the output shows an overview of the system: The first line shows the current time, the running time of the system, the number of users logged in, and the average load on the system.

The average load has three values: the last 1 minutes, the last 5 minutes, and the average load for the last 15 minutes. The larger the value, the higher the average load, the higher the load value for the last 1 minutes, which is normal, because sometimes a process suddenly starts moving, but if the average load of the last 15 minutes is high, the system may be in trouble.

The second line shows the process information for the profile the process in the output of the--top command is called a task: How many processes are running, hibernating, stopped, or ossified.

The next line shows the CPU information. Top divides CPU utilization into several types of output based on the owner (user or system) of the process and the state of the process (running, idle, or waiting).

The following two lines explain the state of the system memory. The forward is the physical memory of the system: how much memory is in total, how much memory is currently used, and how much is idle. The latter line is about the same information, but for the state of the system swap space.

The last part is a detailed list of the running processes-some columns are similar to the PS command output.

    •  pid: Process number of the process.
    • user: The owner name of the process.
    • PR: The priority of the process.
    • ni: The value of the humility of the process.
    • virt: The total amount of virtual memory consumed by the process.
    • res: The total amount of physical memory consumed by the process.
    • SHR: The total amount of memory shared by the process and other processes.
    • s: The state of the process (d for Interruptible sleep State, R for the running state, S for the sleep state, T for the tracking state or stop state, and Z for the rigid state).
    • %CPU: The percentage of CPU time used by the process.
    • %mem: The amount of memory used by the process as a percentage of available memory.
    • time+: The total amount of CPU time since the process started so far.
    • command: The command name of the process, which is the program name that is started.

 by default, the top command the%CPU values are sorted at startup, and you can reorder them with one of the following interactive commands at the top run time. Each interactive command is single-character, and typing the behavior that can change top when the top command is run. The command is shown in the following table:

1 Toggle single CPU state mode and symmetric processor mode
B Open/close bold display of important numbers in a table
I Toggle Irix/solaris Mode
Z Set the color of a table
L Display/Close Average load information line
T displaying/shutting down CPU information lines
M Show/close mem and Swap lines
F Add/Remove different columns of information in the output
O Change the order in which information rows are displayed
F or O Select a column to sort the process
< or > Move the sorted row left or right one column
R Toggle normal sort or reverse order
H Show/Turn off display of threads
C Toggle the command that displays the process, or the full command line input
I Toggles whether the idle process is displayed
S Toggles whether to show cumulative CPU time or relative CPU time
X Turn highlight column on/off
Y Turn on/off highlighting tasks in run
Z Toggle color mode or monochrome mode
B Turn on/off highlight mode for x and Y
U Show a user's process
N or # Set the number of processes to display
K End the specified process (must be a process owner or root user)
R Change the priority of the specified process (must be a process owner or root user)
D or S Change the interval of the update (the default value is 3s)
W Write the current settings to a configuration file
Q Exit the top command

End Process

One of the most important skills of a system administrator is knowing when and how to end a process. Sometimes the process hangs, as long as there is a way to deal with the process to rerun or end the line. Sometimes, however, the process runs out of CPU and does not release resources, and it is time to kill the process.

Linux follows the UNIX approach to interprocess communication, where the signals are communicated between processes on Linux, and the following table lists the meaning and name of the signal representation:

Signal Name Describe
1 HUP Hang Up
2 Int Interrupt
3 QUIT End Run
9 KILL Unconditional termination
11 SEGV Segment Error
15 Term Terminate as much as possible
17 STOP Unconditionally stop running, but do not terminate
18 Tstp Stop or pause, but continue to run in the background
19 CONT Resume running after stop or TSTP

Kill command

The KILL command can signal the process through the PID. By default, the KILL command sends a term signal to all the PID listed on the command line, and unfortunately it can be used only with the process number and not the command name, so it is sometimes not useful.

The-s parameter supports specifying other signals (with signal names or signal values). The KILL command will not have any output. Here's a chestnut:

1 Kill 8080

  It is equivalent to the following chestnuts:

1 Kill 1 8080

Killall command

  The Killall command is very powerful, and it supports ending a process with a process name rather than a process number. The Killall command also supports wildcards, which is useful when the system becomes slow due to heavy load:  

Killall http*

The chestnut command above ends all processes that begin with HTTP, such as the httpd service of the Apache Web server.

Bash shell commands and monitoring that little Thing (ii)

Related Article

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.