Operating system notes-002 process management and multithreading

Some supplementary information, the organizational framework is more arbitrary~

The introduction of processes: After the emergence of multi-program systems, the ability to describe static program concepts is insufficient. A new concept is introduced in order to describe the situation inside the system and describe the activity rules of various operations inside the system.

Process control

Process control primitives

In order to effectively manage the processes in the system, usually the system provides a number of basic operations, these operations are called primitives. Commonly used process control primitives are:

Establishing process primitives
The main task of this primitive is to establish a process control block PCB for the established process and fill in the corresponding initial values. The main operation process is to first apply to the system's PCB space to allocate an idle PCB, and then initialize the PCB entry of the child process according to the parameters provided by the parent process, and finally return a process internal name.
Usually provided parameters: process name (external identifier) ​​n, the initial state of the processor (or the initial value of the process running scene, mainly refers to the initial value of each register and program status word) S0, the priority number k0, the parent process is assigned to the child The initial main memory area M0 of the process and other resource lists (multiple resource tables) R0, etc.
The work of establishing process primitives is roughly described as:

procedure Create(n,S0,k0,M0,R0,acc)
begin
	i:=Get New Internal Name(n); // 调用查找进程名过程,参数为进程外部名。查找对象为PCB集合,如果同名则返回出错信息
	Id(i):=n;
	Priority(i):=k0;
	Cpustate(i):=S0;
	Main Store(i):=M0;
	Resources(i):=R0;
	Status(i):='Readys'; // 设置为‘挂起就绪’
	Parent(i):=*;
	Set Accounting Data; // 在PCB中(或其他相应表中)建立记账信息,这也是调用‘记账过程’
	Insert(RL,i);
end.

Suspend process primitives
can only suspend themselves or their descendants.
The command process is described as follows:

procedure Suspend(n,a);
begin
	i:=Get Internal Name(n);
	S:=Status(i);
	if	S="Running" then STOP(i);
	a:=COPY PCB(i)
	Status(i):=if a="Blockeda" then "blockeds" else "Readys";
	if	S="Running" then SCHEDULER // 调用调用程序SCHEDULER
end.

Unsuspend primitives The unsuspend
process is described as follows:

procedure Resume(n);
begin
	i:=Get Internal Name(n);
	Status(i):=if Status(i)='Readys' then 'Readys' else 'Blockeda';
	if	Status(i)='Readya' then SCHEDULER
end.

Revocation of process primitives There
are two strategies for revocation primitives: 1) only revoke a process with a specified identifier (its child process); 2) revoke one of its child processes and all descendants of the process.
1) It will destroy the hierarchical relationship of the process tree, causing the system to leave some isolated processes, thus losing control over them. Therefore, 2) is generally adopted.
Cancellation primitives are generally issued by the parent process or ancestors, and will not cancel themselves.
A general description of the primitive:

procedure Destroy(n);
begin
	Sched:=false;
	i:=Get Internal Name(n);
	KILL(i);
	if Sched=true then SCHEDULER;
end(Destroy)
procedure KILL(i);
begin
	if Status(i)='Running' then
		begin STOP(I);
			  Sched:=true
		end
	REMOVE(Queue(i),i);
	for all S<- progeny(i) do KILL(S); //<-是数学集合元素中的属于
	for all r<- Resources(i) do RELEASE(r);
								RELEASE(PCB(i));
end(KILL)

Change the process priority number primitive
Omit

Operating system and process control execution

slightly

Multithreading

User-level thread KLT and kernel-level thread ULT

To overcome the shortcomings of pure KLT and pure ULT methods, and get the benefits of these two methods, it is necessary to combine the two methods. This is an operating system based on multithreading. The kernel supports the establishment, scheduling and management of multiple threads. At the same time, the system provides the convenience of a thread library, allowing user applications to establish, schedule and manage user-level threads.

In the text discussion, user-level threads, kernel-level threads, user threads and kernel threads often appear. In fact, the user-level thread ULT and the kernel-level thread KLT are both a management concept , which means that the thread is created and managed by the user or the kernel. In layman's terms, the thread account is in the kernel or in the user application.
Each specific thread in the system has only two types:
(1) User thread: refers to the thread running in the user address space, most threads are user threads.
(2) Kernel thread: refers to the thread running in the kernel space, such as kernel subroutines or all interrupt and exception handlers implemented by threads, they are all kernel threads.

All user-level threads are user threads. All kernel-level threads can be either user threads or kernel threads, depending on the address space in which they run.
Or all interrupt and exception handlers are implemented by threads, they are all kernel threads.

All user-level threads are user threads. All kernel-level threads can be either user threads or kernel threads, depending on the address space in which they run.

Guess you like

Origin blog.csdn.net/MaoziYa/article/details/105719707