Process Management
3.1 Process
A process is a program that is in the execution period (the target code is stored on a storage medium)
However, the process is not confined to a single executable program code.
The execution thread, the thread, is the object of the process activity.
Two virtual mechanisms: virtual processors and virtual memory.
Finally, the program exits execution through the exit () system call.
3.2 Process description and task structure
The kernel stores the list of processes in a two-way circular chain table called the task queue.
The task_struct is relatively large, and it is approximately 1.7KB on 32-bit machines.
3.2. 1 Assigning process descriptors
A task field in a structure holds a pointer to the actual task_struct of the task.
3.2. 2 Storage of process descriptors
The kernel identifies each process through a unique process identity value or PID.
This maximum value is important because it is actually the maximum number of simultaneous processes allowed in the system
3.2.3 Process Status
The processes in the system are bound to be one of the five states in a process.
Task_running (Run)--the process is executable.
Task_interruptible (interruptible)--The process is sleeping (i.e. it is blocked).
Task_uninterruptible (non-interruptible)-less used.
_task_traced--processes that are tracked by other processes.
_task_stopped (stop)--the process stops executing.
3.2.4 Setting the current process state
The kernel often needs to adjust the state of a process.
See the description of the implementation of these related functions in <linux/sched.h>.
3.2.5 Process Context
System calls and exception handlers are explicitly defined interfaces to the kernel.
3.2.6 Process Family Tree
There is an obvious inheritance relationship between the processes of UNIX systems.
So is the Linux system.
Special Reminders:
The cost of iterating through all the processes in a system with a large number of processes is significant.
Therefore, there is not enough reason not to do so.
3.3 Process Creation
UNIX process creation is very different
Decomposition into two separate functions to execute:
Fork ()
Exec ()
3.3.1 Write-time copy
The traditional fork () system call directly copies all the resources to the newly created process.
The actual cost of fork is to copy the page table of the parent process
It is important to create a unique process descriptor for the child process.
3.3.2fork ()
1.fork (), Vfork (), and __clone () call Clone () according to the parameter flags they need.
2. Call Do_fork () from Clone ().
3.do_fork () calls the Copy_process () function and then lets the process start running.
4. Return the Do_fork () function, if the copy_process () function returns successfully, the newly created child process is awakened and put into operation.
3.3.3vfork ()
1. Call copy_process () Yes, the Vfor_done member of TASK_STRUCT is set to null.
2. When Do_fork () is executed, if a specific flag is given, vfor_done points to a specific address.
3. After the child process begins execution, the parent process does not resume execution immediately, but waits until the child process sends a signal to it through the Vfor_done pointer.
4. When calling Mm_release (), the function is used for the process to exit the memory address space and to check if Vfor_done is empty, and if not NULL, a signal is sent to the parent process.
5. Back to Do_fork (), the parent process wakes up and returns.
3.4 Threads implemented in Linux
3.4.1 Creating Threads
3.4.2 Kernel Thread
Kernel threads do not have separate address space, only run in kernel space, never switch to user space, can be dispatched and preempted.
3.5 Process End
1. Delete the process descriptor
2 Orphan process creates a dilemma
Chapter III Reading notes