What to learn in this chapter
------Process Concepts
------process creation, switchover, and revocation
------Process Scheduling
------Process Classification
------Process Status
------Process Management Tools
Introduction
In the Linux system, the function of the kernel is: process management, file system, network function, memory management, driver, security function, etc., in this many modules, process management is a relatively important link, even if it is not as complex as file system and network functions. In process management, the kernel has a very detailed definition of process creation, switching, revocation, and scheduling.
1. Process and related concepts
<1> Process: a process can be understood as an instance of a program execution with a unique PID to identify it, including executable programs and their associated system resources , such as open files, suspended signals, kernel internal data, Processor state, memory address space, and data segments that contain global variables. From the kernel point of view, a process can also be called a task.
<2> Process Descriptor: There are many things related to the process, such as the PID of the process, the State, the priority of the process, the address space of the process, the files that are allowed to access the process, and so on, the Linux kernel specifically designed a type of task_ struct structure, called the process descriptor . The process descriptor contains all the information about the kernel management process, so that you can know all the information about a process as long as you get the process descriptor of a process.
2. Process creation, switching, and revocation
<1> Process Creation : When the system starts, the kernel is loaded on the CPU, then the kernel creates the first process init (SYSTEMD on CENTOS7), and Init creates a variety of sub-processes through the system fork (), and the processes follow the cow mechanism ( That is to modify the data before allocating memory).
<2> Process switching: process Switching is also known as task switching, context switching. It is a behavior that, in order to control the execution of a process, the kernel suspends the process currently running on the CPU and resumes execution of a previously suspended process.
<3> Undo Process: After the process terminates, the kernel needs to be notified so that the kernel frees the resources owned by the process, including memory, open files, and other resources, such as semaphores
3. Process scheduling
<1> scheduling strategy: The scheduling strategy is a set of rules: decide when and how to choose a new process to run. So define a process's priority to satisfy such a strategy. This strategy is represented by a priority of 0-139.
Real-time Priority: 1-99
No need to adjust, the larger the number, the higher the priority
Static priority: 100-139
Can be adjusted, the smaller the number, the higher the priority
Priority is measured by the Nice value
nice:-20----19, found in task_struct structures
<2> scheduling algorithm: Early Linux, the scheduling algorithm is based on the priority of the process to select the "best" process to execute, its disadvantage is that the time overhead and "the number of running processes". Some scheduling algorithm must satisfy a function relationship, the industry is called Big O
Big O: The relationship between time complexity, timing, and scale. Yes:
O (1), O (Logn), O (n) linear, O (n^2) parabolic, O (2^n)
4. Process Type
Classification criteria for <1> process one:
Daemon: daemon, process initiated during system boot, and terminal-independent process
Foreground process: terminal-related, process initiated through terminal
Note: The two can be converted to each other
Classification criteria for <2> Process II:
Cpu-bound:cpu intensive, non-interactive (graphics)
Io-bound:io intensive, Interactive (operation)
5. Process status
processes that run in memory also have a variety of States
Operating State r:running
Ready state: Readiness
Sleep state
Interruptible s:interruptable
Non-disruptive d:uninterruptable
Stop state t:stopped, paused in memory, but not dispatched unless manually started
Zombie Z:zombie, end process, child process not closed until parent process ends
6. Signal received by the process
<1> common signal: Man 7 signal
1) SIGHUP: No need to close the process and let it reread the configuration file
2) SIGINT: Abort the running process, equivalent to CTRL + C
9) SIGKILL: Kill the Running process
SIGTERM: Terminating a running process
Sigcont: Continue Running
SIGSTOP: Background hibernation
<2> How to specify the signal:
(1) Digital identification of the signal; 1, 2, 9
(2) Signal complete name; SIGHUP
(3) abbreviated name of the signal; HUP
7. Process management Tools
<1>ps aux
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/86/F3/wKioL1fPsIDCHV0BAAGF6aa_zDI491.jpg "title=" 9.jpg " Width= "height=" 158 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:158px; "alt=" Wkiol1fpsidchv0baagf6aa_zdi491.jpg "/>
User: Users running the process
PID: Process ID
%cpu: CPU Usage
%MEM: Memory consumption
VSZ: Virtual Memory Set
RSS: Actual memory set
TTY: Terminal information
STAT: Process Status
Start: Process run start time
Time: Runtime
COMMAND: Process Name
You can also display information with specific options
Ps-axo PID, Comm,%cpu,%mem, state, TTY, Euser, Ruser
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/86/F4/wKiom1fPs0rimN5zAADe2LSLPlE923.jpg "title=" 8.jpg " alt= "Wkiom1fps0rimn5zaade2lslple923.jpg"/>
The above also proves that the passwd is applicable to suid permissions, although the user is users, but its really effective is the root
<2>uptime
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/86/F4/wKioL1fPuy7A5Su5AABP2Afi92E316.jpg "title=" 7.jpg " alt= "Wkiol1fpuy7a5su5aabp2afi92e316.jpg"/>
Boot time
Run time
Number of users logged in
Average load: Refers to the average number of processes running in a queue during a specific time interval
First minute load
Five minute load
Tenth minute load
Note: The average load of 1, 5, 10 minutes is generally no more than 1
Reference value: If the current number of active processes per CPU core is not greater than 3, then the performance of the system is good. If the number of tasks per CPU core is greater than 5, then there is a serious problem with the performance of this machine.
If the Linux host is 1 dual-core CPUs, the load average 6 indicates that the machine is fully used.
<3>top
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/86/F6/wKiom1fPwpTyoAdnAAI5SPDB4JM569.jpg "title=" 5.jpg " Width= "height=" 243 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:243px; "alt=" Wkiom1fpwptyoadnaai5spdb4jm569.jpg "/>
Tasks
Total: Number of processes
Running: Number of running processes
Sleeping: Number of dormant state processes
Stopped: Number of stop State processes
Zobie: Number of dead state processes
%CPU (s)
Us:user space: Percentage of CPU occupied by the user
Sy:system: CPU Percentage of kernel space Note: High load: Us:sy=7:3
Ni:nice Modifying the percentage of CPU consumed by nice values
Id:idle Idle CPU Percentage
wa:wait percentage of CPU waiting for IO to complete
Hi:hardware interrupt hard interrupt consumes CPU percentage
Si:software Interrupt Soft Interrupt consumption CPU percentage
St:stole The stolen CPU, such as VMware
Buffer: buffered: Meta data
Cache: Caching: Data
PID: Process Number
User: Process Initiator
Pr:priority: Priority
NI:Nice:nice value
VIRT: Virtual Memory Set
RES: Resident Memory Set
SHR: Shared Memory set
S:status: Status
%CPU:CPU occupancy ratio
%MEM: Memory consumption ratio
Time+: Run duration
COMMAND: Start the process
Sort:
P: As percentage of CPU occupied,%cpu
M: Occupy memory percentage,%MEM
T: Cumulative CPU Duration, time+
The first message shows:
Uptime information: l command
Tasks and CPU information: T command
CPU Display: 1 (digital)
Memory Information: M command
Exit Command: Q
Modify Refresh time interval: s
Terminates the specified process: K
Save File: W
ESC: Exit
View process numbers directly pidof COMMAND or PS aux | grep * *----->kill
<4>htop
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/86/F7/wKiom1fP0BCjzJ8vAAUL53ILZdo725.jpg "title=" 4.jpg " Width= "height=" 383 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:383px; "alt=" Wkiom1fp0bcjzj8vaaul53ilzdo725.jpg "/>
More advanced process management software than top
F1 Help
F2 switching CPU, MEM, swap display mode
F10 exit
Select Process Execution K
<5>vmstat: Viewing disk throughput
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/86/F7/wKiom1fP0tOQA_Q4AADefO6sBf8620.jpg "title=" 3.jpg " Width= "height=" 102 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:102px; "alt=" Wkiom1fp0toqa_ Q4aadefo6sbf8620.jpg "/>
R: Number of processes waiting to run, related to the number of cores
B: Number of processes in non-interruptible sleep state (length of blocked queue)
Swap
SI: Data rate for swapping into memory from disk (KB/S)
So: Data rate from memory swap to disk (KB/S)
Io:
BI: The rate at which data is read into memory from a block device (KB/S)
Bo: The rate at which data is saved to block to memory
<6>glances650) this.width=650; "Src=" http://s5.51cto.com/wyfs02/M02/86/F6/ Wkiol1fp2eiaulfzaarq8rem570930.jpg "title=" 2.jpg "width=" "height=" 359 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:359px; "alt=" Wkiol1fp2eiaulfzaarq8rem570930.jpg "/> H: Help information Characteristic c/S structure
Server side: glances-s-B IP
Client side: Glances-c IP <7>dstat
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/86/F8/wKiom1fP2oGhaLMMAAHqNGgIo9o300.jpg "title=" 1.jpg " Width= "height=" 318 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:318px; "alt=" Wkiom1fp2oghalmmaahqnggio9o300.jpg "/>
Disk reads and writes can be tested via DD If=/dev/sdb Of=/dev/zero
Network monitoring can be tested by Ping-f ip-s 65507.
This article is from the "Linux_home" blog, make sure to keep this source http://dmwing.blog.51cto.com/11607397/1847408
Linux System Process Management