Linux process management .md

Linux Process Management

1. The basic process outlined

Process is started to run executable program examples.

/ Proc directory under the name of the directory in digital, each directory represents a process that holds attribute information process. PID of each process is unique, even if the process exits, and other processes will not take up its PID.

Part 1.1. Process

Allocated memory address space
security attributes, including ownership credentials and privileges of
a program code or multiple threads of execution
process status

1.2. Process environment

Local and global variables
of the current context of the scheduled
allocation of system resources, such as file descriptors and network ports

Generating 1.3. Process

Existing (parent) process to copy its own address space (fork) to create a new (child) process structure.
Each new process is assigned a unique process ID (PID), to meet the needs and safety of the track. PID of the parent process ID (PPID) are elements of the new process environment.
Any process can create a child process. All processes are descendants of the first system processes. On RHEL7, the first system process is systemd.

By fork routine child inherits the security identity, past and current file descriptors, ports and resources privileges, environment variables, and program code. Subsequently, the child could exec their own code. Typically, the parent child process during operation in a sleep state, a setting request (the wait) signal upon completion of the process. Upon exiting, the child may have been closed or dropped their resources and the environment, and the remaining part is called a zombie. Parent process receives a signal to be awakened in the child process exits, clearing the remaining structure, and then continue with its own code.

1.4 Classification Process

Foreground process: a process associated with the terminal, the terminal starts the process by
Note: it can also be started in the foreground of the process sent to the host in order to protect operating mode
daemon: independent daemon, the terminal processes (e.g., the kernel), the guide system during the start of the process

2. Process Status

Excuting // Run state
Ready // ready state, it can also be referred to a sleep state
Uninterruptible sleep // uninterruptible sleep. Not ready to wake up only when the IO resource loaded successfully to wake
Interruptible sleep // can interrupt sleep. You can always wake
Zombie // zombie process. Finishes running normally, but does not release the memory occupied
Stopped // stop state, pause in memory, but will not be scheduled unless manually start the
cause of the sleep process:
When executing a process, you need to load additional IO resources , because of the slow speed IO device, it goes into a sleep state to wait, to hand over the CPU to other processes, so as not to waste the remaining time of execution
in multi-tasking operating system, each CPU (or CPU core) at a time a point on the processing process. In the process runs, its direct request of CPU time and resource allocation subject to change. Process is assigned a status, which along with environmental requirements change.

2.1.Linux process status

Kernel defined state flag name and description
R TASK_RUNNING: the process is executing on the CPU, or is waiting to run. When (or run) in operation state, the process may be executing user or kernel routines routines (system call), or queued and ready
S TASK_INTERRUPTIBLE: the process is sleeping and is waiting for a certain condition: hardware request, the system resource access or signal. When an event or signal this condition is satisfied, the process returns to operation
D TASK_UNINTERRUPTIBLE: This process also sleep, but different from the S state, the response signal is not transmitted. Use only under certain conditions, which can cause unexpected interruptions in the process of device status
K TASK_KILLABLE: the process is sleeping, the same D status can not be interrupted, but has been modified to allow the task waiting by the response signal is interrupted (completely out). Utilities usually interrupted process will be displayed as D status
T TASK_STOPPED: the process has been stopped (pause), usually a signal sent by the user or other processes. The process can be returned through another signal to a running state, continue (resume)
T TASK_TRACED: being debugged process will be stopped temporarily, and share the same status flag T
Z EXIT_ZOMBIE: child process send a signal to the parent process when you exit . All resources except the process identification (PID) have been released
X EXIT_DEAD: When a parent process to clean up (get) the remaining sub-process structure, process and now has been completely released. This status will not be seen from the listed utility in the process
<high-priority process
N low-priority process

  • Foreground process group process
    | multithreaded process
    s First Session process

    3. Process Priority

    3.1.Linux process scheduling and multi-tasking

    Modern computer systems include both instructions and only allows a low-end processor, comprising high-performance supercomputer, supercomputers each with hundreds of the CPU, having a plurality of cores on each of the CPU, they may be performed in parallel hundreds of instruction. But all these systems tend to have one thing in common: they need to run a number of processes always exceeds the number of core actually has.

By the time slicing technique, Linux (and other operating systems) actual (and threads) to run the process can exceed the actual number of processing units available. Operating system process scheduler will quickly switch between processes on a single core, giving the user the impression of a kind of running multiple processes at the same time.

Perform this switch part of the Linux kernel called process scheduler.

3.2. Process Priority

Process Priority range: 0-139, the lower the number, the higher the priority
0-99: real-time priority, the kernel adjustment
100-139: static priority, the user can control

High priority process characteristics:
get more CPU time
more priority access to CPU run

To modify the priority of a process can be achieved by adjusting the process nice value, the smaller the nice value, the higher the priority:
the range is nice value (-20,19) - 139 corresponding to 20 corresponds to 100,19

3.3. Relative priority

Because not every process and other processes are equally important, you can inform the scheduler uses different scheduling policies for different processes. Most scheduling processes running on conventional systems used called SCHED_OTHER (also known as SCHED_NORMAL), but there are other strategies can be used for different purposes.

Since not all processes are created in the same way, you can specify the relative priority for the introduction of process SCHED_NORMAL policy run. This process is called priority nice value. A process can have 40 different levels of nice value.

These nice levels range from -20 to 19. By default, the process will inherit the parent process nice level, usually 0

The higher the nice level, the lower the priority (the process CPU usage is easy to give other processes)
the lower the nice level, the higher the priority (the process even less inclined to give up the CPU)
fight if resources do not exist use (for example, when the number of active processes than the number of available CPU cores), even the nice high-level process will still use all available CPU resources that may be available. But when the number of CPU time to process requests exceeds the available number of cores, higher than the lower-level processes nice nice level of process receives less CPU time

3.4.nice levels and permissions

Set a lower level might be nice is very CPU-resources processes adversely affect the performance of other processes running on the same system, so only allow the root user to set negative nice nice-level and lower-level existing processes.

Ordinary non-privileged user is only allowed to set a positive nice level. Nice level can only enhance the existing process, but can not be reduced nice level.

3.5. Process priority adjust

Process Priority: Adjustment nice value

// adjustment process has started nice value:
renice the NI PID (Example: renice 3 3704)
// specified nice value at startup: (- 20, 19)
nice -n the NI the COMMAND

[root@localhost ~]# ps -elF|grep vi
4 S root 730 1 0 80 0 - 24938 poll_s 6196 0 09:13 ? 00:00:00 /usr/bin/VGAuthService -s
4 S root 2427 1409 0 80 0 - 31577 poll_s 1692 0 14:24 pts/0 00:00:00 vi abc
0 S root 2430 2410 0 80 0 - 28169 pipe_w 984 0 14:26 pts/1 00:00:00 grep --color=auto vi
[root@localhost ~]# renice 10 2427
2427 (进程 ID) 旧优先级为 0,新优先级为 10
[root@localhost ~]# ps -elF|grep vi
4 S root 730 1 0 80 0 - 24938 poll_s 6196 0 09:13 ? 00:00:00 /usr/bin/VGAuthService -s
4 S root 2427 1409 0 90 10 - 31577 poll_s 1692 0 14:24 pts/0 00:00:00 vi abc
0 R root 2433 2410 0 80 0 - 28169 - 984 0 14:27 pts/1 00:00:00 grep --color=auto vi
[root@localhost ~]# ls
abc test
[root@localhost ~]# nice -n 19 vi abc

4. The process management command

Each file information about each process of Linux systems are stored in the / proc / PID directory

4.1.ps

ps (process state) command lists the current process. You can display detailed process information, including:

User identifier (the UID), which is determined privileged processes
unique process identifier (the PID)
the CPU and the real time is spent
assigned to the process at various locations on the amount of memory
location STDOUT process, called the control terminal
of the current process status

ps format supports three options:

UNIX (POSIX) option, can be grouped but must begin with a hyphen
BSD options may be grouped and the hyphen but not with the use
GNU long option to double hyphen at the beginning

ps (process state), display process information. Precautions:

Plus the [] brackets, expressed kernel threads, usually located on the top
exiting zombie process or defunct representation

// common options:
A // display all terminal-related processes
u // display process which is initiated by the user
x // display all associated with a terminal process

-e // all processes, the same effect -A
-l // displayed in long format
-F // full format display more detailed process information
-f // full format display more detailed process information
-H / / display process-related information to process hierarchical format
-o // according to their need to select the fields to be displayed

// aux analytical results:
VSZ SIZE // Virtual Memory, Virtual Memory set
RSS // ReSident Size, permanent memory set
STAT // process status
when the cumulative run time of long-TIME //

// ps command parsing result:
the NI // Nice value
PRI // priority
PSR // processes run on which CPU core
RTPTRIO // real-time priority
C // CPU running number of
start-up time STIME // process
VSZ // virtual memory SiZe, virtual memory set
RSS // reSident Size, permanent memory set
STAT // process status
when the cumulative run time of long-tIME //

[root@localhost ~]# ps aux |head 
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 129108 6472 ? Ss 09:13 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0.0 0.0 0 0 ? S 09:13 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 09:13 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 09:13 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 09:13 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 09:13 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R 09:13 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S 09:13 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 09:13 0:00 [kdevtmpfs]
[root@localhost ~]# ps -elf |head 
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 - 32277 ep_pol 09:13 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
1 S root 2 0 0 80 0 - 0 kthrea 09:13 ? 00:00:00 [kthreadd]
1 S root 3 2 0 80 0 - 0 smpboo 09:13 ? 00:00:00 [ksoftirqd/0]
1 S root 5 2 0 60 -20 - 0 worker 09:13 ? 00:00:00 [kworker/0:0H]
1 S root 7 2 0 -40 - - 0 smpboo 09:13 ? 00:00:00 [migration/0]
1 S root 8 2 0 80 0 - 0 rcu_gp 09:13 ? 00:00:00 [rcu_bh]
1 R root 9 2 0 80 0 - 0 - 09:13 ? 00:00:00 [rcu_sched]
5 S root 10 2 0 -40 - - 0 smpboo 09:13 ? 00:00:00 [watchdog/0]
5 S root 12 2 0 80 0 - 0 devtmp 09:13 ? 00:00:00 [kdevtmpfs]
[root@localhost ~]# ps -F
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
root 1409 1405 0 28880 2204 0 09:13 pts/0 00:00:00 -bash
root 2470 1409 0 37766 1784 0 14:41 pts/0 00:00:00 ps -F
[root@localhost ~]# ps -f
UID PID PPID C STIME TTY TIME CMD
root 1409 1405 0 09:13 pts/0 00:00:00 -bash
root 2471 1409 0 14:41 pts/0 00:00:00 ps -f

4.2.pstree

pstree process tree for display on the current system

[root@localhost ~]# pstree
systemd─┬─NetworkManager─┬─dhclient
        │ └─2*[{NetworkManager}]
        ├─VGAuthService
        ├─agetty
        ├─auditd───{auditd}
        ├─chronyd
        ├─crond
        ├─dbus-daemon───{dbus-daemon}
        ├─firewalld───{firewalld}
        ├─lvmetad
        ├─master─┬─pickup
        │ └─qmgr
        ├─polkitd───5*[{polkitd}]
        ├─rhnsd
        ├─rhsmcertd
        ├─rsyslogd───2*[{rsyslogd}]
        ├─sshd─┬─sshd───bash───pstree
        │ └─sshd───bash
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        ├─tuned───4*[{tuned}]
        └─vmtoolsd───{vmtoolsd}

4.3.pgrep

Grep style to specify which processes to show only in the current system in line with the process of looking for certain characteristics. Show only the process ID

[root@localhost ~]# pgrep vi
730
2500
[root@localhost ~]# ps -ef|grep vi
root 730 1 0 09:13 ? 00:00:00 /usr/bin/VGAuthService -s
root 2500 1409 0 14:54 pts/0 00:00:00 vi abc
root 2526 2410 0 15:00 pts/1 00:00:00 grep --color=auto vi

4.4.pidof

Find its PID number in accordance with the process name

[root@localhost ~]# ps -ef|grep vi
root 730 1 0 09:13 ? 00:00:00 /usr/bin/VGAuthService -s
root 2500 1409 0 14:54 pts/0 00:00:00 vi abc
root 2526 2410 0 15:00 pts/1 00:00:00 grep --color=auto vi
[root@localhost ~]# pidof vi
2500

4.5.vmstat

Virtual Memory Status View command
// syntax: vmstat [Options] [Delay [COUNT]]
// Example:
vmstat 2 // represents every 2 seconds to refresh
vmstat 2 5 // represents refresh every 2 seconds, 5 times refresh exit

// common options:
-s // display memory statistics

procs:
R & lt (running) // represents a queue length of the waiting operation, i.e., the number of processes running wait
b (block) // represents a blocking queue length, i.e. the number of processes in uninterruptible sleep state of
Memory:
swpd / / exchange the total memory usage
free // free physical amount of memory
buffer // buffer for the total amount of memory
cache // amount of memory for cache
swap:
Si (swap in) // indicate how much physical memory paged into the swap, i.e., data of the incoming data rate swap (kB / S)
SO (swap OUT) // swap represents how many pages from physical memory into the converter, i.e. the data rate of data leaving the swap (kB / S)
IO :
BI (in block) // indicates how many disk blocks are transferred to the memory, i.e., the rate of data read from a block device to the system (kB / S)
BO (block OUT) // indicates how many disk blocks rate (kb / s) from memory to the hard drive are synchronized, and also to a block of data that is stored in the apparatus
System:
in (interrupts) // represents the number of interrupts, i.e., interrupt rate (kb / s)
CS (context switch) // represents the number of context switches, that process The slew rate (kB / S)
the CPU:
US // represents a user space
sy // represents kernel space
id // represents idle percentage
wa // Wait indicates the percentage of time occupied IO Completion
st // represents steal, stolen virtualization technology time (such as running a virtual machine)

[root@localhost ~]# vmstat 
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 1 0 0 1483472 3008 225880 0 0 9 1 40 41 0 0 100 0 0
[root@localhost ~]# vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 1 0 0 1483472 3008 225880 0 0 9 1 40 41 0 0 100 0 0
 0 0 0 1483476 3008 225880 0 0 0 0 67 71 0 0 100 0 0
 0 0 0 1483476 3008 225880 0 0 0 0 71 72 0 0 100 0 0
 1 0 0 1483476 3008 225880 0 0 0 0 81 77 0 0 100 0 0
 0 0 0 1483476 3008 225880 0 0 0 0 61 66 0 1 100 0 0
[root@localhost ~]# vmstat -s
      1867024 K total memory
       154520 K used memory
       130336 K active memory
       115732 K inactive memory
      1483616 K free memory
         3008 K buffer memory
       225880 K swap cache
      2097148 K total swap
            0 K used swap
      2097148 K free swap
         1229 non-nice user cpu ticks
            9 nice user cpu ticks
         2988 system cpu ticks
      2099312 idle cpu ticks
         2695 IO-wait cpu ticks
            0 IRQ cpu ticks
          166 softirq cpu ticks
            0 stolen cpu ticks
       179796 pages paged in
        23257 pages paged out
            0 pages swapped in
            0 pages swapped out
       844377 interrupts
       859142 CPU context switches
   1569201184 boot time
         2674 forks

The job control

5.1. Work session

Job control shell is a feature that allows a single instance of the operation and management of a plurality of shell commands.

Shell prompt input job in each conduit associated. All processes in the pipeline are part of the job, and is a member of the same process group. (If only the shell prompt, type a command, this command can be regarded as minimum pipe command. The command will be the only member of the job)

Only one job and keyboard input read signal generated from a specific terminal window. Processes belonging to the job is the control terminal of a foreground process.

The background process control terminal is any member of the other jobs associated with the terminal linked. Background processes of the terminal can not read or receive keyboard input from the terminal to generate an interrupt, but can be written to the terminal. Background jobs may have stopped (pause), also may be running. If a running background job tries to read the contents from the terminal, the job will automatically pause.

Each terminal is its own session, and may have a plurality of separate foreground process and background process. A job can only belong to a session, which session control is part of the terminal.

5.2 The job classification

Linux work is divided into two kinds of background foreground job with the job. Their respective characteristics are as follows:

Foreground job: The terminal starts, and after the start has been dominated by the command prompt

Background job: a terminal can start, but after starting, the release command prompt, subsequent operations done in the background
while running in the background such job is sent, but it is still associated with the terminal. If desired sent to the host, the relationship between the release and the terminal needs to be performed (nohup COMMAND &)

5.3. In the background work

// keep & symbols after the command can generate a background job
@ Jobs command to display all current background jobs

[root@localhost ~]# sleep 800 &
[1] 2305
[root@localhost ~]# jobs 
[1]+ 运行中 sleep 800 &

// When only a background job, use the fg command directly, it can not be transferred to the foreground with a background job any parameters, but when there are multiple jobs, you must keep up with the job number +%, which is above the command execution results the number in [] enclosed.

// Use ctrl + z foreground process may be sent to the background, then the job is stopped

[root@localhost ~]# sleep 600 &
[2] 2307
[root@localhost ~]# sleep 500 &
[3] 2308
[root@localhost ~]# jobs
[1] 运行中 sleep 800 &
[2]- 运行中 sleep 600 &
[3]+ 运行中 sleep 500 &
[root@localhost ~]# fg %3
sleep 500
^Z
[3]+ 已停止 sleep 500
[root@localhost ~]# jobs
[1] 运行中 sleep 800 &
[2]- 运行中 sleep 600 &
[3]+ 已停止 sleep 500

// use the bg command + job number allows the background stopped job rerun
// kill add kill job number can manually specify a job
// result in jobs command
+ // command will default job operation
- // command the default action of the second job

[root@localhost ~]# jobs
[1] 运行中 sleep 800 &
[2]- 运行中 sleep 600 &
[3]+ 已停止 sleep 500
[root@localhost ~]# bg %3
[3]+ sleep 500 &
[root@localhost ~]# jobs
[1] 运行中 sleep 800 &
[2]- 运行中 sleep 600 &
[3]+ 运行中 sleep 500 &
[root@localhost ~]# kill %3
[root@localhost ~]# jobs
[1] 运行中 sleep 800 &
[2]- 运行中 sleep 600 &
[3]+ 已终止 sleep 500

6. Inter-Process Communication

Inter-Process Communication (IPC: Inter Process Communication)

Inter-process communication:

The same host
shared memory
signal: Signal

Different hosts
rpc: remote procecure call
based on the inter-process communication socket implementation

7. Use the signal control process

Signal is transmitted to the process of software interrupt. Report to the Executive signal event in the program. Event signal may be generated error, or external events (such as I / O request or a timer expires), or from an explicit request (e.g., using the transmission command signal)

The following table lists the basic signaling system administrator for the daily process management. Please refer to signals in the short name (the HUP) or proper name (SIGHUP).

A method specified signals:
signal number (identification number): kill -1
Signal Full Name: kill -SIGKILL
Signal abbreviated name: kill -TERM or kill -KILL or kill -INT or kill -HUP

The basic process management signal

Signal Number
| ID | Short Name | definitions | use |
|: ----------- |: ---------- |: ----------- ---------- |: --- |
| 1 | HUP | suspended | for a process without restarting can reread the configuration file, and let the new configuration take effect |
| 2 | INT | keyboard interrupt | interrupt a foreground process. ctrl + SIGINT signal c is used |
| 9 | KILL | interrupted and can not intercept | lead to immediate termination of the program. Can not be intercepted, ignored or treated |
| 15 defaults | TERM | terminate | lead to program termination. And SIGKILL different, can be intercepted, ignored or treated. Friendly approach requires the program terminates, allowing self-cleaning |
Users can interrupt their processes, but only root can terminate processes owned by other people.

kill command sends a signal to a process according to the ID. Although the name of the signal to kill, but the order may be used to transmit any signal, not just the program termination

// syntax: the kill [-Signal] PID ...
// display all available signals (man 7 signal can be used to view help information)

[root@localhost ~]# kill -l
 1) SIGHUP  2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT 7) SIGBUS   8) SIGFPE   9) SIGKILL  10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX 

/ Killall COMMAND: killall followed by process name, it said it would match the process to kill all processes named names

[root@localhost ~]# ps -ef|grep sleep
root 2340 1412 0 14:27 pts/0 00:00:00 sleep 500
root 2341 1412 0 14:27 pts/0 00:00:00 sleep 800
root 2342 1412 0 14:28 pts/0 00:00:00 sleep 900
root 2344 1412 0 14:28 pts/0 00:00:00 grep --color=auto sleep
[root@localhost ~]# killall sleep
[1] 已终止 sleep 500
[2]- 已终止 sleep 800
[3]+ 已终止 sleep 900
[root@localhost ~]# ps -ef|grep sleep
root 2348 1412 0 14:28 pts/0 00:00:00 grep --color=auto sleep

8. Monitoring Process Activity

8.1. IO load

Load-aware for some time within the average of the representative system load. Linux is implemented by the expected average load is calculated wait time of service representation.

Linux not only count the number of processes, but also to calculate the number of threads as a separate task. Running threads and wait I / O CPU resource thread request queue corresponding to the R and D process status. Waiting for I / O includes tasks in sleep while waiting for the expected disk and network response.

Belongs to the global counter counts the number of load, the total sum of all the CPU. As the task returns from sleep may be rescheduled to a different CPU, each CPU is difficult to accurately count, but the accuracy of the cumulative number of possible protection. The display represents the average load of all CPU.

// Check the number of cpu core

[root@localhost ~]# grep 'model name' /proc/cpuinfo 
model name  : Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz

Some UNIX system considers only run queue lengths or CPU utilization to instruct the system load. Because idle CPU system may be due to a disk or network resource busy and encountered a very long wait, so the average load Linux included consideration of I / O's. Experiencing high load average but low CPU activity, check the disk and network activity.

Linux can be used in top, uptime displays the load average.

[root@localhost ~]# uptime 
 14:34:30 up 5:21, 1 user, load average: 0.00, 0.01, 0.05

//此处的load average就表示负载平均值,这三个值代表最近1、5和15分钟的负载情况。

Divided by the average number of logical CPU load in the system will display. When the value of less than 1 indicates better resource utilization, waiting time is very short. When the value is higher than 1 indicates the saturation of resources, but also a certain service latency.

The number of idle CPU load queue is 0. Each thread is ready and waiting to make the count increased by one. The total number of queue 1, the resources (CPU, disk, or network) is in use, but not spend time waiting for the request. Increase in the cumulative number of requests will be counted, but many requests can be processed within the time limit, resource usage will be high, and the waiting time will not.

Because the disk or network resource busy waiting for I / O is in a sleeping processes included in this count, and the average value of the load increases. Although it can not represent CPU utilization, queue number still indicates that the user is waiting for resources and program services.

Before resource saturation, the average load will remain at 1 or less, because almost will not find a job waiting in the queue. Only the resource request results in a saturated state and is left in the load queue timing calculation routine, the average load will increase. When resource utilization close to 100% for each additional request will begin to experience the service latency.

8.2. Real-time process monitoring

top for full screen display of dynamic system information

//常用选项:
    -d      //设置延迟时长,top -d 1表示每隔1秒刷新一次,默认每隔5秒刷新
    -b      //批模式翻屏显示,默认只实时显示一屏,若要显示后面的进程信息则可使用-b选项,与-n #合用,可指定显示翻#屏
    
[root@localhost ~]# top -b -n 1
top - 14:38:24 up 5:25, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 152 total, 1 running, 151 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1867024 total, 1523364 free, 151264 used, 192396 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1527400 avail Mem 

   PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  2376 root 20 0 157584 2080 1476 R 6.2 0.1 0:00.01 top
     1 root 20 0 129104 6468 2704 S 0.0 0.3 0:01.94 systemd
     2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
     3 root 20 0 0 0 0 S 0.0 0.0 0:00.39 ksoftirqd/0
     5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
     7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
     8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
     9 root 20 0 0 0 0 S 0.0 0.0 0:00.97 rcu_sched
    10 root rt 0 0 0 0 S 0.0 0.0 0:00.25 watchdog/0

load average:1分钟,5分钟,15分钟
    load average    //CPU队列中等待运行的任务的个数
cpu(s):多颗CPU平均负载,按1键显示每颗CPU平均负载。
    us  //表示用户空间;
    sy  //表示内核空间;
    ni  //表示调整nice值,CPU占用的比率;
    id  //表示空闲百分比;
    wa  //表示等待IO完成所占据的时间百分比;
    hi  //表示hard interrupt,硬件中断占据的时间百分比;
    si  //表示软中断占据的时间百分比;
    st  //表示steal,被虚拟化技术偷走的时间(比如运行虚拟机)
PR      //优先级
NI      //nice值
VIRT    //虚拟内存集
RES     //常驻内存集
SHR     //共享内存大小
S       //进程状态

//top命令交互式子命令:
    M   //根据驻留内存大小进行排序,默认根据CPU百分比排序
    P   //根据CPU使用百分比进行排序
    T   //根据累计时间(占据CPU时长)进行排序
    l   //是否显示平均负载和启动时间
    t   //是否显示进程和CPU状态相关信息
    m   //是否显示内存相关信息
    c   //是否显示完整的命令行信息
    q   //退出top命令
    k   //终止某个进程
    1   //显示所有CPU的信息
    s   //修改刷新时间间隔

Guess you like

Origin www.cnblogs.com/liping0826/p/11578247.html
Recommended