Process creation so that we may wish to look at how to create one from the user-space process.
User space tasks and tasks of the underlying mechanisms of the kernel is the same, because they will depend on a do_fork functions to create a new process. When you create a kernel thread, the kernel will call a function named kernel_thread (see./linux/arch/i386/kernel/process.c), this function will perform some initialization call do_fork. The system calls the function you may have seen system call model. In many cases, the system call named sys_ * and provides some initial function to call (such as error checking or user space behavior). Actual work is often delegated to another named do_ * functions. Create a user-space process is similar. In user space, a program calls fork, this will lead to a kernel function sys_fork system calls (see./linux/arch/i386/kernel/process.c). Function as shown in Figure 1. Figure 1 is responsible for creating a process hierarchy of function from Figure 1, you can see the process of creating do_fork is. You can find in./linux/kernel/fork.c do_fork function (as well as cooperation function copy_process). Alloc_pidmap do_fork function first calls, the call will be assigned a new PID. Next, check whether the debugger do_fork in tracking the parent process. If this is set within the clone_flags CLONE_PTRACE flag to do perform preparations fork action. After the function is also called do_fork copy_process, passing these signs, stack, the registry, the parent process and the latest distribution of PID. New processes within the function as a parent copy_process process to create a copy. This function can do apart from initiated process of all of the boot process after processing. Copy_process within the first step is to verify that the CLONE flag to ensure that these labels are consistent. If not, it returns EINVAL error. Next, ask LinuxSecurityModule (LSM) at the current task is to create a new task. To learn more about LSM in Security-EnhancedLinux (SELinux) context, see the references section. Next, call dup_task_struct function (./linux/kernel/fork.c), which will allocate a new task_struct and set the current process of descriptors is copied to. In the new thread stack settings, some state information will be initialized and returns control to the copy_process. Control back to copy_process, apart from a few other restrictions and security check, you will perform a number of general management, including in the new various initialization on the task_struct. After calling a number of replication function to copy all aspects of this process, such as replication and open file descriptors (copy_files), copy the symbol information (copy_sighand and copy_signal), the replication process memory (copy_mm) and, ultimately, the replication thread (copy_thread). After that, the new task is assigned to a handler, while allowing the execution process of handlers for additional checks (cpus_allowed). New process priority from the parent process priority inheritance, a small number of additional general management and control is returned to the do_fork. At this point, the new process exists but has not yet run. Do_fork function by calling wake_up_new_task to fix this problem. This function (which can be found in the./linux/kernel/sched.c) initializes some of the Scheduler's general management information, the new process is placed in the run queue, and then wake up for execution. Finally, once you go back to the PID value do_fork is returned to the calling program, the process is complete. Process scheduling processes exist in Linux are also available through Linux scheduler is dispatched. Although the Scheduler is beyond the scope of this article, but the Linux scheduler is maintained for each priority level of a list, save the task_struct references. Task through the schedule function (./linux/kernel/sched.c) call it under load and process execution history determine the best process. In this article's reference section to learn more about Linux version 2.6 Scheduler for more information. Process destroy destruction process through several event-driven — through normal processes end, through the signal or through a call to the exit function. Regardless of the process how to exit the process end must rely on kernel function do_exit (/linux/kernel/exit.c in.). This process is shown in Figure 2. 2. the implementation of the function that processes destroy hierarchy do_exit aims will all reference to the current process to remove from the operating system (for all no shared resources). The process to be destroyed by setting flags to indicate the process PF_EXITING is exiting. Other aspects of the kernel will use it to avoid process is removed also attempts to deal with this process. The process from it in their lives during various resources-separation from each other through a series of calls to the implementations, such as exit_mm (delete memory page) and exit_keys (release thread sessions, and processesSecurity key). Do_exit functions do the release process required a variety of statistics, and after that, by calling exit_notify performs a series of notifications (for example, to inform the parent process its child processes are exit). Finally, process status is changed to PF_DEAD and also invokes the schedule function to select a new process will be executed. Please note that if a notice to the parent process is required (or process is being followed), then the task will not disappear completely. If you do not need any notification, you can call the practical withdrawing release_task to use by a process that part of memory. Closing Linux still evolving, one further innovation and optimization of the area is process management. At the insist on principle of UNIX, Linux has been a breakthrough. A new processor architecture, symmetric multiprocessing (SMP), and virtualization will cause the kernel to make further progress in the field. One example is the Linux version 2.6 introduced in the new O (1) Scheduler, it has a large number of tasks of system provides scalability. Another example is the use of NativePOSIXThreadLibrary (NPTL) updated the threading model, and before the LinuxThreads model, it provides more effective Threading.
No comments:
Post a Comment