Process Management and scheduling
Process type: Binary code application, single thread, resource assigned to application, new process is fork and exec system call generation, and clone is used to implement thread.
Namespaces:
Concept
The C + + namespace gives the user a different interface interface. In a virtualized system, a single physical computer can run multiple cores. All resources are abstracted through namespaces. In essence, namespaces establish different views of the system.
Realize
UTS namespace, User namespace
Process ID Number
UNIX processes always assign a number to uniquely identify them in their namespace, which is called the process ID number, or PID.
Process ID
In addition to the PID, there are several other IDs.
Namespaces increase the complexity of PID management.
Managing PID
The kernel needs to find a way to manage local variables within all namespaces, as well as other IDs.
Data
Function
Generate a unique PID
A large bitmap is used to track the PID cores that have been allocated and still available, where each PID is identified by a bit.
2.3.4 Process Relationship
Parent process, child process
2.4 Process Management-related system calls
This section discusses the implementation of the fork and Exec series system calls.
Usually these calls are not emitted directly by the application, but rather through a middle-tier call, the C standard library that is responsible for communicating with the kernel.
The way to switch from a user state to a kernel mentality varies depending on the architecture.
For now, consider the kernel as a "library" for use by the C standard library. (Although the kernel is a complex thing, it is a lot simpler in the view of library invocation, just as simple as the Java call package.) )
2.4.1 Process Replication
The system calls used in traditional UNIX for the replication process are fork, but Linux implements 3.
(1) Fork is a heavyweight call, creating a full copy of the parent process
(2) Vfork, sharing data between parent and child processes
(3) clone, generate thread, the parent-child process sharing, replication for precise control.
1. Copy-on-write
When copying data, a process typically uses only a small portion of its memory pages. (Then how do you know which part to copy?) )
2. Performing system calls
The entry points for system calls to fork, Vfork, and clone are the Sys_fork, sys_vfork, and Sys_clone functions, respectively. The task of the above function is to extract the information provided by the user space from the processor register, calling the architecture-independent do_fork function, which is responsible for process replication. (Does the latter refer to Do_fork?) )
3. Implementation of Do_fork
All 3 fork Mechanisms eventually call the Do_fork in KERNEL/FORK.C (an architecture-independent function).
4. Replication process
The specific work of the copy process is done in do_fork.
5. Special issues when creating threads
The user space line libraries uses the clone system tune to generate a new thread. But one thing to keep in mind is that in the Linux kernel, the difference between a thread and a normal process is not so rigid, and these two nouns are often used as synonyms.
2.4.2 Kernel Thread
Kernel threads are processes that are initiated directly by the kernel itself.
Kernel threads actually delegate kernel functions to stand-alone processes that execute "in parallel" with other processes in the system.
2.4.3 Start a new program
1. EXECVE implementation
The entry point for the system call is an architecture-related SYS_EXECVE function that quickly delegates its work to a system-independent process DO_EXECVE routine.
Search_binary_handler is used to find an appropriate binary format at the end of Do_execve for the specific file to be executed.
2. Interpreting binary formats
2.4.4 Exit Process
The process must be terminated with the exit system call, giving the kernel an opportunity to release the resources used by the process back to the system.
The entry point for the call is the Sys_exit function, which requires an error code as its argument in order to exit the process. The definition is architecture-independent, see kernel/exit.c. We are not interested in its implementation because it will soon entrust the work to Do_exit.
In short, the implementation of this function is to reduce the individual reference counter by 1, if the reference counter is 0 and no process to use the corresponding structure, then the corresponding memory area is returned to the memory management module.
Implementation of the 2.5 scheduler
A unique description of each process is saved in memory and is connected to other processes through several structures. This is the case with the scheduler, whose task is to share CPU time between programs, creating the illusion of parallel execution. As discussed above, the task is divided into two different parts: one involving a scheduling policy and another design context switch.
I just look at the operating system of the book, do not require to understand, process