The Shadowless Sword Fragment 7 (Process and Scheduled Tasks)

 

 

Process concept

The function of the kernel: process management, file system, network functions, memory management, drivers, security functions, etc.
Process: A copy of the running program is an instruction set that is loaded into the memory
Process ID (Process ID, PID) number It is used to mark each process
UID, GID, and SELinux context to determine access and access rights to the file system,
usually inherited from the user who executes the process.
Life cycle
task struct: Linux kernel storage process information data structure format
task list : Linked list
process creation composed of task structs of multiple tasks :
init: the first process
parent-child relationship
process: all created by its parent process, CoW
fork(), clone()

Basic states and transitions of a process

the basic state of the process

Creation status : When the process is created, it needs to apply for a blank PCB (process control block), fill in the information of the control and management process, and complete the resource allocation. If the creation work cannot be completed, for example, the resources cannot be satisfied, it cannot be scheduled to run. The state of the process at this time is called the creation state
ready state : the process is ready, the required resources have been allocated, and as long as the CPU is allocated, it can be immediately Running
execution state : After the process is in the ready state and is scheduled, the process enters the execution state.
Blocking state : The executing process is temporarily unable to run due to some events (I/O request, failure to apply for a buffer area), and the process is blocked. Enter the ready state when the request is satisfied and wait for the
termination state of the system call : the process ends, or an error occurs, or is terminated by the system, and enters the termination state. can no longer be executed

Six cases of transition between states

Running -> Ready : 1, mainly because the process occupies the CPU for too long, and the system allocates a limited time for the process to occupy the CPU; 2, in the system using the preemptive priority scheduling algorithm, when there are higher When the priority process wants to run, the process is forced to give up the CPU, and the process changes from the execution state to the ready state.
Ready -> Running : When the time slice of the running process is used up, the scheduling will go to the ready queue to select the appropriate process to allocate the CPU
to run -> Blocking : The executing process cannot be executed due to a waiting event, then the process is executed byexecution state becomes a blocking state. If an I/O request
is blocked -> ready : the event that the process is waiting for has occurred, it will enter the ready queue
. The following two states are impossible:
blocking -> running : even if given The blocking process allocates the CPU and cannot be executed. The operating system does not select from the blocking queue when scheduling, but selects
ready from the ready queue -> blocking : the ready state is not executed at all, and it is impossible to enter the blocking state.

Process priority

Process priority:
0-139 (CentOS4, 5)
each has 140 running queues and expired queues
0-98, 99 (CentOS6)
real-time priority: 99-0 value maximum priority highest
nice value: -20 to 19, corresponding to System priority 100-139 or 99
Big O: time complexity, time and scale relationship
O(1), O(logn), O(n) linear, O(n^2) parabolic, O(2^n ) system priority: the lower the number, the higher the priority

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325281040&siteId=291194637