Process Termination | ||||||||||
there are two system calls that terminate a User Mode application: | ||||||||||
· The exit_group( ) system call, which terminates a full thread group, | ||||||||||
that is, a whole multithreaded application | ||||||||||
exit_group( ) | ||||||||||
do_group_exit( ) | ||||||||||
do_exit( ) | ||||||||||
· The _exit( ) system call, which terminates a single process, | ||||||||||
regardless of any other process in the thread group of the victim | ||||||||||
_exit( ) | ||||||||||
do_exit( ) | ||||||||||
The do_group_exit( ) function | ||||||||||
1,Checks whether the SIGNAL_GROUP_EXIT flag of the exiting process is not zero, | ||||||||||
which means that the kernel already started an exit procedure for this thread group. In this case, | ||||||||||
it considers as exit code the value stored in current->signal->group_exit_code, and jumps to step 4 | ||||||||||
2,Otherwise, it sets the SIGNAL_GROUP_EXIT flag of the process | ||||||||||
and stores the termination code in the current->signal->group_exit_code field | ||||||||||
3,Invokes the zap_other_threads( ) function to kill the other processes in the thread group of current, | ||||||||||
if any. In order to do this, the function scans the per-PID list in the PIDTYPE_TGID hash table corresponding to current->tgid; | ||||||||||
for each process in the list different from current, it sends a SIGKILL signal to it (see Chapter 11). | ||||||||||
As a result, all such processes will eventually execute the do_exit( ) function, and thus they will be killed. | ||||||||||
4,Invokes the do_exit( ) function passing to it the process termination code | ||||||||||
The do_exit( ) function | ||||||||||
1. Sets the PF_EXITING flag in the flag field of the process descriptor to indicate that the process is being eliminated | ||||||||||
2. Removes, if necessary, the process descriptor from a dynamic timer queue via the del_timer_sync( ) | ||||||||||
3. Detaches from the process descriptor the data structures related to paging, semaphores, | ||||||||||
filesystem, open file descriptors, namespaces, and I/O Permission Bitmap, respectively, | ||||||||||
with the exit_mm( ), exit_sem( ), _ _exit_files( ), _ _exit_fs(), exit_namespace( ), and exit_thread( ) functions. | ||||||||||
These functions also remove each of these data structures if no other processes are sharing them | ||||||||||
4. If the kernel functions implementing the execution domain and the executable | ||||||||||
format (see Chapter 20) of the process being killed are included in kernel modules, t | ||||||||||
he function decreases their usage counters | ||||||||||
5. Sets the exit_code field of the process descriptor to the process termination code. | ||||||||||
This value is either the _exit( ) or exit_group( ) system call parameter | ||||||||||
or an error code supplied by the kernel | ||||||||||
6. Invokes the exit_notify( ) function | ||||||||||
7. Invokes the schedule( ) function | ||||||||||
Process Removal | ||||||||||
void release_task(struct task_struct * p) | ||||||||||
1. Decreases the number of processes belonging to the user owner of the terminated process. | ||||||||||
2. If the process is being traced, the function removes it from the debugger's ptrace_children list | ||||||||||
and assigns the process back to its original parent | ||||||||||
3. Invokes _ _exit_signal() to cancel any pending signal and to release the signal_struct descriptor of the process | ||||||||||
4. Invokes _ _exit_sighand() to get rid of the signal handlers | ||||||||||
5. Invokes _ _unhash_process( ), which in turn | ||||||||||
6,signal to the parent of the leader to notify it of the death of the process | ||||||||||
7. Invokes the sched_exit( ) function to adjust the timeslice of the parent process | ||||||||||
8. Invokes put_task_struct() to decrease the process descriptor's usage counter; | ||||||||||
if the counter becomes zero, the function drops any remaining reference to the process | ||||||||||
Understanding the linux kernel-ch3-Destroying Processes
最新推荐文章于 2024-09-18 08:47:26 发布