Process Removal

The Unix operating system allows a process to query the kernel to obtain the PID of its parent process or the execution state of any of its children. A process may, for instance, create a child process to perform a specific task and then invoke a wait( ) -like system call to check whether the child has terminated. If the child has terminated, its termination code will tell the parent process if the task has been carried out successfully.

To comply with these design choices, Unix kernels are not allowed to discard data included in a process descriptor field right after the process terminates. They are allowed to do so only after the parent process has issued a wait( ) -like system call that refers to the terminated process. This is why the task_zombie state has been introduced: although the process is technically dead, its descriptor must be saved until the parent process is notified.

What happens if parent processes terminate before their children? In such a case, the system could be flooded with zombie processes that might end up using all the available task entries. As mentioned earlier, this problem is solved by forcing all orphan processes to become children of the init process. In this way, the init process will destroy the zombies while checking for the termination of one of its legitimate children through a wait( ) -like system call.

The release_task( ) function releases the process descriptor of a zombie process by executing the following steps:

1. Decrements by 1 the number of processes created up to now by the user owner of the terminated process. This value is stored in the user_struct structure mentioned earlier in the chapter.

2. Invokes the free_uid( ) function to decrement by 1 the resource counter of the user_struct structure.

3. Invokes unhash_process( ), which in turn:

a. Decrements by 1 the nr_threads variable b. Invokes unhash_pid( ) to remove the process descriptor from the pidhash hash table c. Uses the remove_links macro to unlink the process descriptor from the process list d. Removes the process from its thread group, if any

4. Invokes the free_task_struct( ) function to release the 8-KB memory area used to contain the process descriptor and the Kernel Mode stack.

I [email protected] RuBoard

Was this article helpful?

0 0

Post a comment