Process Termination


Terminating a process

When a process terminates, the kernel releases the resources owned by the process and notifies the child’s parent.

A Process can be terminated in 2 ways:

  1. Self induced when it calls exit()
  2. Initiated when it receives a signal or exception

In both cases, the termination is done via the code block do_exit()

  1. It sets the PF_EXITING flag in the flags member of the task_struct.
  2. It calls del_timer_sync() to remove any kernel timers.
  3. If BSD process accounting is enabled, do_exit() calls acct_update_integrals() to write out accounting information.
  4. It calls exit_mm() to release the mm_struct held by this process. If no other process is using this address space—if the address space is not shared—the kernel destroys it.
  5. It calls exit_sem(). If the process is queued waiting for an IPC semaphore, it is dequeued here.
  6. It then calls exit_files() and exit_fs() to decrement the usage count of objects related to file descriptors and filesystem data. If either usage counts reach zero, the object is no longer in use by any process, and it is destroyed.
  7. It sets the task's exit code, stored in the exit_code member of the task_struct, to the code provided by exit() or whatever kernel mechanism forced the termination.The exit code is stored here for optional retrieval by the parent.
  8. It calls exit_notify() to send signals to the task’s parent, reparents any of the task’s children to another thread in their thread group or the init process, and sets the task’s exit state, stored in exit_state in the task_struct structure, to EXIT_ZOMBIE.
  9. do_exit() calls schedule() to switch to a new process. do_exit() never returns

The task is not runnable (and no longer has an address space in which to run) and is in the EXIT_ZOMBIE exit state

The only memory it occupies is its kernel stack, the thread_info structure, and the task_struct structure.The task exists solely to provide information to its parent. After the parent retrieves the information, or notifies the kernel that it is uninterested, the remaining memory held by the process is freed and returned to the system for use.

results matching ""

    No results matching ""