Linux Process Management
Process is: Running the program
Allocation units for resources: memory resources, CPU resources, I/O resources
Kernel Features: Process management
The kernel manages processes through resource allocation.
How is the CPU resource allocated?
Cutting time slice, time slice rotation
Inter-process switching: Save the scene, especially the instruction pointer, the address where the next instruction is located
Save site:
Save the metadata for the process
Process metadata: Describes the properties of a process
The kernel tracks the status of the process: saving the scene saves the state of the previous process to the kernel.
The kernel is a special kind of data structure stored process state, namely task_struct
Recovery site:
Pick by priority
Process priority (used to pick the next process to run)
Priority level: 0-139
0-99: The higher the real-time priority value, the higher the priority level
100-139: The smaller the static priority value, the higher the priority
Nice value, adjust the priority value of the user space, the range is-20 19, corresponding to 100-139
It is not possible to traverse all the priorities, as the traversal also consumes the CPU, but instead traverses the 140 priority queues one at a-
There's a cost to switching between processes.
Status of the process
Non-disruptive sleep
Zombie State: Zombies process, regular scan, and clear
The process is always initiated by the parent process
But the first process Init was created by the kernel and is the parent process of all processes
Inter-process communication: IPC
Process communication between the same host:
Signal: Signal
Shared Memory: SHM
Semaphore: Semerphor
Process communication between different hosts:
RPS: Remote Procedure Call (this Is how NFS communicates)
Socket: Socket
Pstree: Displays the command tree of the current Linux system
PS: Shows the status of the process
PS Options
There are two styles of options, with no-
Common combinations of options:
PS aux user-centric display and terminal-related and unrelated all processes
A displays information about all processes related to the terminal
x display information for all processes that are not related to the terminal
U display the status of a process as a user-centric
PS A
PS X
Time: The sum of the times to occupy the CPU
PS AX
Ps-ax
Field Meaning:
%cpu execution of commands, CPU usage
%MEM execution of commands, MEM utilization
VSZ: Virtual Memory Set
RSS: Resident memory set, i.e. not allowed to swap out memory size
STAT: Status of the process
R:running Running state
S: Can interrupt sleep state
D: Non-disruptive sleep state
T: Stop state
Z: Zombie State
S: Indicates that the process is a leader process, that is, the first process that Prtree prints out
+: Indicates that the process is a foreground process
L: Indicates that the process is a multithreaded process
N: Low-priority process
<: high-priority process
[]: Indicates that this is a kernel thread
Ps-ef
-e: Show All Processes
-F: Show full format
Field:
PPID: The parent process for the process
Ps-efh
-F: Show additional information
-H: Show hierarchy of processes
Field:
Stime: Start time
Pgrep Process Filtering Tool
-U UID Displays the process initiated by the specified user
-T terminal shows the terminal's own PID
-l display Process PID while displaying process name
ID Apache
Pgrep-u 48
Pgrep-t tty1
Pgrep-lu 48 48 for-U parameters
Pidof gets the PID number of the process based on the process name
PIDOF Process Name
Pidof httpd
Top dynamically view process information, and supports interactive operations
Default CPU usage is sorted from highest to lowest
Shift+m: Sort Memory utilization
SHIFT+T:CPU cumulative time Occupation rate
SHIFT+P:CPU cumulative time Occupation rate
1: Load per CPU core is displayed separately
Vmstat know.
Message: Signal process communication between the same host
Kill-l list types of interprocess communication
Common signal:
1 Sighup Let the program reread the configuration file without restarting the process
2 SIGINT interrupts a running process CTRL + C
9 SIGKILL forces a running process to be killed
Sigterm gracefully kills a running process
Sigcont the process of stopping the state is running.
Sigstop turn a process into a stop state CTRL + Z
Kill manually sends a signal other than SIGINT to a process
Kill-Signal PID
The format of the signal is:
-1
-sighup
-hup
Kill PID Default Pass-15 signal
Killall manually sending signals to certain processes
Killall-Signal Process name
Killall httpd Default pass-15 signal
FG runs the process of a stopped state
Linux Process Management