Linux View process commands (top)

Source: Internet
Author: User

An operating system that supports multitasking is not a computer that does many things at the same time, but quickly rotates to perform these tasks. Linux schedules different programs to wait for the CPU to be used.

How the process works:

When the system starts, the kernel first initializes its own program into a process, then runs an init program, and then Init runs a series of shell scripts called Init that can start all system services (/etc/init/). Many of these processes appear as daemons (daemon), run only in the background, and do not have any user interfaces. This way, at least the system is performing some transactions even if the system is not logged on.

View Linux system process commands are: Top, PS, lsof, netstat

Top: View the system's resource status (Dynamic view process, which is updated every 3 minutes by default)

$ top |head

top-16:07:41 up 7:14, 2 users, load average:
Tasks:195 Total, 1 running, 194 sleeping, 0 stopped, 0 zombie
%CPU (s): 3.8 us, 1.0 sy, 0.0 ni, 94.3 ID, 0.9 wa, 0.0 hi, 0.0 si, 0.0th
KiB mem:3996960 Total, 2624532 used, 1372428 free, 126300 buffers
KiB swap:4000764 Total, 0 used, 4000764 free. 1466592 Cached Mem

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND2160 vobile 0 54504 13768 3608 S 6.2 0.3 1:10.25 Ibus-daemon

2450 vobile 0 322668 72600 30316 S 6.2 1.8 6:27.18 Compiz
3034 vobile 0 158688 25084 14120 S 6.2 0.6 0:55.09 gnome-terminal

It is divided into two parts, the above City system summary, the following is the process list, the process list is CPU utilization sort.

Line number
Field
Significance

1
Top Program Name
1
16:07:41 Current time
1
Up 7:14 The time the system is running normally (from boot to present)
1
2 users There are 2 users logged into the system
1
Load average Load average, which is the number of processes waiting to run, which share the CPU. Shows three values, each of which corresponds to a different time period. The first is the average of the last 60 seconds, the next is the average of the first 5 minutes, and the last is the average of the first 15 minutes. An average of less than 1.0 indicates that the computer is not busy.
2
tasks:1Total Number of processes
2
Running Processes that are running or ready to run
2
Sleeping Is sleeping, waiting for an event, such as a button or a package
2
Stopped Stopped, the process has been instructed to stop running
2
Zombie A dead process or a zombie process, a child process that has been terminated, and its parent process has not emptied it
3
%CPU (s) Characteristics of the process that the CPU is executing
3
3.8 US 3.8% of the CPU is being used for userprocesses. This means that the process is outside the kernel
3
1.0 sy 1% of CPU time is used for system (kernel) processes
3
0.0 ni 0% of CPU time is used for the "nice" (low-priority) process
3
94.3 ID 94.3% of the CPU time is idle
3
0.9 WA 0.9% CPU time to wait for I/O
3
0.0 hi
3
0.0 si
3
0.0 St
4
KiB Mem Demonstrate the use of physical memory
5
KiB Swap Show usage of swap partitions (virtual memory)

Field
Significance
Pid Process number
USER User ID Process Owner
PR Priority levels for each process
NI Values for each priority
VIRT Virtual Memory Size
Res Resident memory Size (KB) code+data
Shr The amount of shared memory that the process uses
S
Status of the process d= non-disruptive sleep state r= run s= sleep t= track/stop z= zombie Process
%cpu CPU utilization (percentage of CPU time and total time that the process has occupied since the most recent refresh)
%MEM Memory utilization (the percentage of total memory that the process consumes in physical memory)
time+ Total CPU time elapsed since the process was started
COMMAND The command name of the process

(The amount of physical memory the code executable consumes, and the amount of physical memory that the data segment + stack uses outside of the executable code

Virtual memory is an imaginary memory space in which portions of the virtual memory space that need to be accessed are mapped to physical memory space during the program's run. Large virtual memory space can only indicate that the program can be accessed during the process of larger space, does not mean that the physical memory space consumption is also large.

Resident memory, as the name implies, is the physical memory that is mapped to the process virtual memory space.

Virt represents the size of the process virtual memory space.

The meaning of res refers to the size of the part of the process virtual memory space that has been mapped to the physical memory space.

See how much memory the process occupies during operation should look at R the value of s instead of the value of Virt. )

Interactive commands for top:

R can reverse the current sort.

P Sort by percent CPU usage q This option will cause top to refresh without any delay, and if the calling program has Superuser privileges, top will run at the highest priority level

R reschedule a process's priority level

Ctrl+l Erase and rewrite the screen
H or? Display the help screen and give a brief summary of the commands.
K Terminates a process.   The user will be prompted for the process PID to be terminated and what signal needs to be sent to the process. The normal termination process can use a 15 signal, and if not, use signal 9 to force end the process. The default value is signal 15. This command is masked in safe mode.
I ignore idle and zombie processes. This is a switch-type command.
Q quit the program.
R reschedule the priority level of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value lowers the priority and, conversely, it gives the process a higher priority. The default value is 10.
S switch to cumulative mode.
s changes the delay time between two refreshes. The user will be prompted to enter a new time in S. If there are decimals, it is converted into Ms. Enter a value of 0 and the system will continue to refresh, the default value is 5s. It is important to note that if you set too small a time, it is likely to cause a constant refresh, so it is too late to see the display, and the system load will be greatly increased.
F or F Add or remove items from the current display.
O or O change the order in which items are displayed.
L Toggle Display Average load and start time information.
M toggles display memory information.
T toggles the display of process and CPU status information.
The C toggle Displays the command name and the full command line.
M sorts based on the size of the resident memory.
P is sorted according to the percentage size of CPU usage.
T is sorted by time/accumulated time.
W writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files

Top [-] [d] [P] [Q] [C] [C] [s] [s] [n]

Parameter description:

d Specifies the interval between every two times the screen information is refreshed, and of course the user can use the s interactive command to change
P only monitors the status of a process by specifying the monitoring process ID
S switch to specified cumulative mode
s enables the top command to run in Safe mode. This will remove the potential danger of interactive commands
I make top not show any idle or zombie process
C Displays the entire command line instead of just displaying the command name

eg:/usr/bin/top-b-d 1-n 1---output 1 times per 1s

Linux View process commands (top)

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.