1, the static characteristics of the process
Process: an instance of program execution
Process Descriptor (TASK_STRUCT): basic information for the process (thread_info), pointer to memory area descriptor (MM_STRUCT), process-related TTY (tty_struct), current directory (fs_struct), pointing to file descriptor The pointer (files_struct), the received signal (SIGNAL_STRUCT)
Process Status: 1, operational status (task_running): Running or ready to execute
2. interruptible wait State (task_interruptible): Process hangs, generates hardware interrupt, received signal is awakened into task_running state
3. Non-interruptible waiting State (task_uninterruptible): similar to above; cannot be interrupted
4. Paused state (task_stopped): Execution of the process is paused
5. Tracking status (task_traced):
6, Zombie State (Exit_zombie): The execution of the process is terminated, but the parent process does not publish the wait () class system call, the kernel cannot discard the data contained in the dead process descriptor
7. Zombie Revocation State (Exit_dead): The parent process publishes the wait () class system call, and the process is deleted by the system. In order to avoid competition from other processes, the process is changed from zombie state to zombie revocation state.
PID: Process descriptor processid,32 bit system default upper 32767, 64-bit system default upper 4194303. Use bitmap to vote PID idle state
Magic Number constant: 2^32 is a golden section, taking the nearest prime to this value. i.e. 0x9e370001 (2 654 404 609) = 2^31 + 2^29-2^25 + 2^22-2^19-2^16 +1
Process Resource limitations: Linux, the process of system resources occupied by some restrictions, to avoid excessive use of system resources users; CPU time, address space, file size, heap size, stack size, number of processes, etc.
2. How the kernel processes the process switch
Hardware context: Each process has its own address space, but the CPU registers must be shared, and a set of data that must be mounted before the process is restored is called a hardware hardware.
Before the process switches, the hardware context needs to be switched on, and the hardware contexts that are switched on are saved in the thread field of the Process Descriptor field thread_struct. Additionally, the value of the universal register remains in the kernel stack.
Process switch: 1, switch the page Global directory to install a new address; 2. Switch kernel stacks and hardware contexts
There are also other registers or coprocessors: FPU (arithmetic floating point unit), MMX (Multi Media extension Multimedia extension instruction set), SSE/SSE2 (streaming SIMD Extensions), etc. to consider switching; SIMD (single-instruction multiple-data single instruction multi-data)
3, the creation of the process
Ways to improve the efficiency of creating processes: copy-on-write, lightweight processes (which allow parent-child processes to share many data structures in the kernel), vfork () create processes that share the memory address space of the parent process.
Three ways to create a process: Clone (), fork (), Vfork ()
Clone (): Create a lightweight process
Fork (): Implemented by Clone (), with different parameters passed in
Vfork (): Implemented by Clone (), with different parameters passed in
Process 0:swapper process, idle process; in multiprocessor systems, each CPU has a process 0
Process 1: The kernel process, which shares data with process 0, also known as the Init process, creates and monitors all process activity performed on the outer layer of the operating system.
4. Revocation of the process
Exit (): System call to terminate a process
Exit_group (): System call, terminating the entire thread group
Zombie Process: One reason is that the parent process is dead and cannot call the wait function to end the child process and release its process descriptor. This time you need to force the child process to be called the INIT process's child process, which is notified by Init to release
5, Linux multi-threaded program support
Deep understanding of the Linux kernel-processes