Table of contents
3. The process environment includes
2. Describe the process status
1. Basic process management signals
2. The default action for each signal
3. Log off the account as an administrator
Fourth, monitor process activities
(2) Interpretation of data related to load balancing
(3) Explanation of CPU load balancing
1. Process
1. Definition
A process is a running instance of an executable program that has been started
2. Composition
The address space of the allocated memory
Security properties, including all credentials and privileges
One or more threads of execution of program code
process state
3. The process environment includes
local and global variables
current scheduling context
Allocated system resources, such as file descriptions conforming to network ports
4. Process life cycle
The existing parent process copies its own address space (fork) to create a new child process structure. Each new process is assigned a unique process ID (PID) to meet tracking and security requirements. PID and parent process ID (PPID ) is an element of the new process environment, any process can create child processes, and all processes are descendants of the first system process
By forking a process, the child process inherits security identities, past and current file descriptors, ports, resource privileges, environment variables, and program code. Subsequently, the child process may exec its own program code. Typically, the parent process sleeps while the child process is running, setting up a request (wait) to signal when the child process completes, and upon exiting, the child process has closed or discarded its resources and environment. The only remaining resource, called a zombie, is an entry in the process table. When the parent process receives a signal when the child process exits, it is awakened, and the process table of the child entry is cleaned up, thereby releasing the last resource of the child process. Then, the parent process continues to execute its own program code.
2. Describe the process status
name |
the sign |
Kernel-defined state names and descriptions |
run |
red |
TASK_RUNNING: The process is executing on the CPU, or waiting to run. When in the running (or runnable) state, a process may be executing a user routine or a kernel routine (system call), or it may be queued and ready |
to sleep |
S |
TASK_INTERRUPTICLE: Is the process waiting for a certain condition |
to sleep |
D |
TASK_UNINTERRUPTICLE: This process is also sleeping, but unlike the S state, it will not respond to signals. Use only in situations where process interruption may result in an unexpected device state |
to sleep |
K |
TASK_KILLABLE: The same as the non-interruptible D state, but modified to allow the waiting task to respond to a signal to be interrupted (completely exited) |
to sleep |
I |
TASK_REPORT_IDLE: A subset of the D state, when calculating the load balancing value, the kernel will not count these processes |
stopped |
T |
TASK_STOPPED: The process has been stopped (suspended) |
stopped |
T |
TASK_TRACED: The process being debugged will also be temporarily stopped and share a T state flag |
Freeze |
Z |
EXIT_ZOMBIE: The child process signals the parent process when it exits |
Freeze |
X |
EXIT_DEAD: the process is now cleanly released when the current parent process cleans up (acquires) the remaining child process structures |
3. Related commands
1. top command
The S column shows the status of each process. On a single-CPU system, only one process can run at a time. You can see that there are multiple R processes. Not all processes are running, and some are waiting.
2. ps command
Used to list the current process, display more detailed information including:
(1) User UID, which determines the privileges of the process
(2)PID
(3) CPU and actual time spent
(4) The amount of memory allocated by the process in various locations
(5) The location of the process stdout, called the control terminal
options:
-aux The most common set of options, displays all processes including those without a controlling terminal.
-lax Provides more technical details, but speeds up display by avoiding querying usernames.
-ef Use options similar to UNIX syntax.
-j Displays job-related information.
Processes in square brackets (usually at the top of the list) are scheduled kernel threads
Zombies are listed as exiting and defunct
ps output is one-time, top can update the output in real time
ps can adopt a tree display format, which is convenient for viewing the relationship between parent and child processes
2. Interrupt the process
1. Basic process management signals
signal number |
short name |
definition |
use |
1 |
HUP |
hang up |
Used to report the termination of an interrupt controlling process, and also to request that a process reinitialize (reload configuration) without terminating |
2 |
INT |
keyboard interrupt |
Causes program termination, can be intercepted or processed, sent by pressing the INTR key sequence (ctrl+C) |
3 |
QUIT |
keyboard exit |
Similar to SIGINT, adds a process dump on termination. Sent by pressing the QUIT key sequence (ctrl+\) |
9 |
KILL |
Interrupt, unable to intercept |
Causes immediate program termination, cannot be intercepted, ignored or handled, always fatal |
15 |
TERM (default) |
termination |
Causes the program to terminate. Unlike SIGKILL, it can be intercepted, ignored, and required to terminate the program in a "friendly" way; allowing self-cleaning |
18 |
CONT |
continue |
Sent to the process to resume it (if stopped). Cannot be intercepted, always resumes process even if handled |
19 |
STOP |
stop, stop |
Suspended process, cannot be intercepted or handled |
20 |
TSTP |
keyboard stop |
Unlike SIGSTOP, which can be intercepted, ignored or processed, it is sent by pressing the SUSP key sequence (ctrl+Z) |
2. The default action for each signal
terminate - causes the program to terminate immediately (exit)
Core Dump - causes the program to save a memory image (core dumped) and then terminate
stop - causes the program to stop executing (pause), and then wait to continue (resume)
3. Related commands
(1) kill command
This command sends a signal to a process based on its PID number, this command can be used to send any signal, not just a kill signal
options:
-l lists the names and numbers of all available signals
(2) killall command
Signals can be sent to multiple processes based on the command name
(3) pkill command
Send a signal to one or more processes that meet the criteria, selected by command name, processes owned by a specific user, or all system-wide processes. The pkill command includes advanced selection criteria:
command: process with a command name that matches the pattern
UID: Is the process owned by a certain Linux user account, whether valid or real
GID: A process owned by a Linux group account, whether valid or real
parent: a child process of a specific parent process
Terminal: A process running on a specific controlling terminal
3. Log off the account as an administrator
To log off a user, first determine the login session to be terminated, use the w command to list the user's login and currently running processes, and record the TTY and FROM columns to determine the session to be closed
All user login sessions are associated with a terminal device (TTY). If the format of the device name is pts/N, it means that this is a pseudo-terminal associated with a graphical terminal window or a remote login session. If the format is ttyN, then Indicates that the user is at a system console, alternate console, or other directly attached terminal device
Fourth, monitor process activities
1. Load balancing
(1 Introduction
Load balancing means sensing system load over a period of time, reporting the number of processes ready to run on the CPU and the number of processes waiting for disk or network I/O to complete
(2) Interpretation of data related to load balancing
Three averages represent 1, 5, 15 minute load cases
(3) Explanation of CPU load balancing
The process that needs CPU time is the reason for increasing the number of loads. You can divide the displayed load balance value by the number of logical CPUs in the system. If it is lower than 1, the resource utilization rate is good and the waiting time is short. If it is higher than 1, it means the resource saturation. High, long waiting time.
The idle CPU queue has a load number of 0, each process waiting for the CPU to process will increase the load number by 1, if there is a process running on the CPU, the load number is 1, although the resource (CPU) is in use, but there is no waiting It is required that if the process runs for a full minute, then its contribution to the load balancing for 1 minute is 1.