[Go] Process creation-end flowchart

Source: Internet
Author: User

from:http://blog.csdn.net/xinyuan510214/article/details/50516279

Arch/x86/include/asm/unistd_32.h:fork () User space to invoke (such as a C program)--->int $0x80 generates 0x80 soft interrupt--->ARCH/X86/KERNEL/ENTRY_32.S: ENTRY (System_call) Interrupt handler System_call ()---> EXECUTE save_all macro to save all CPU register values--->ARCH/X86/KERNEL/SYSCALL_TABLE_32.S:  ENTRY (sys_call_table) system calls a multi-path decomposition table--->arch/x86/kernel/process_32.c:sys_fork ()--->kernel/fork.c:do_fork ()  Copying the original process becomes another new process--->kernel/fork.c:copy_process ()--->struct task_struct *p; Define a new process descriptor (PCB)---the legality check of the >CLONE_FLAGS flag--->security_task_create () security check (SELinux mechanism)--->kernel/fork.c:dup_  Task_struct () copy process descriptor--->struct thread_info *ti; Defines the thread information structure--->alloc_task_struct () allocates memory for the new PCB--->kernel/fork.c:arch_dup_task_struct () copies the PCB---of the parent process >atomic_ Set (&tsk->usage,2) sets the PCB usage counter to 2, which indicates the active state--->copy_creds () Copy Permissions and identity information---> The total number of detection processes is more than max_threads---> Initialize each field in the PCB--->sched_fork () Scheduler Related Settings---> Replication process All Information Copy_semundo (), Copy_files (),--->copy_signal (), copy_mm () --->copy_thread () replication Thread--->alloc_pid () assigning PID--->Update properties and number of processes count--->kernel/sched.c:wake_up_new_task () put the process on the run queue and let the Scheduler Dispatch--->KERNEL/SCHED.C:SELECT_TASK_RQ () Select the best CPU (multiple CPUs in SMP)--->p->state = task_running is set to task_running State--->activate_task ()--->enqueue_task ( Inserts the current process into the runqueue of the corresponding CPU---> has clone_vfork flag: wait_for_completion () blocks the parent process, waits for the child process to end---> returns the assigned PIDKERNEL/SCHED.C : Schedule () Dispatches a newly created process process running in exit () User space to invoke (such as a C program)--->0x80 interrupt jumps to Include/linux/syscalls.h:sys_exit ()--->kernel/ex    It.c:do_exit () is responsible for the exit of the process--->struct task_struct *tsk = current; Get my PCB--->set_fs (user_ds) settings using the file system mode--->exit_signals () clear the signal handler function and set the PF_EXITING flag---> Purge process a series of resources exit_mm (), Exit_files ()--->exit_fs (), Exit_thread ()--->kernel/exit.c:exit_notify () exit Notification--->forget_original_parent (  Take all my sub-processes to the INIT process--->kill_orphaned_pgrp () sends a pending signal to processes within the process group SIGHUP and sigcont--->tsk->exit_signal = SIGCHLD; Sends a SIGCHLD signal to my parent process--->kernel/exit.c:do_notify_parent () notifies the parent process---> if the parent process processes the SIGCHLD signal, returns DEATH_REAP---> if the parent process does notProcesses the SIGCHLD signal, returns the signal value passed in--->__wake_up_parent () wakes the parent process---> Notification returns DEATH_REAP, sets Exit_state to Exit_dead I quit and die---> Otherwise set me up for Exit_zombie I quit but didn't die, become a zombie process---> If death_reap:release_task () I clean up related resources myself---> If it's zombie, I'll adopt the INIT process when my parent process exits.    The--->exit_io_context () cleanup IO context--->preempt_disable () is cleared by init to disable preemption--->tsk->state = task_dead; Set me for process death State--->kernel/sched.c:schedule () release my PCB, schedule another new process to clean up the zombie process: Wait system call waits for child process to end--->0x80 interrupt last reached kernel/ Exit.c:do_wait ()--->do_wait_thread ()--->wait_consider_task ()---> If the child process is exit_dead, return the 0,wait call back, The subprocess cleans itself---> if the child process is Exit_zombie:wait_task_zombie ()--->xchg () sets the zombie subprocess to Exit_dead--->release_task () cleans up the zombie subprocess

  

[Go] Process creation-end flowchart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.