Process Part 2: Operating System
Process Part 2: Operating System
O P E R AT I N G S Y S T E M
CONTEXT SWITCH
• Interrupts cause the OS to change CPU from its current task and to run a kernel routine
• Such operations happen frequently on general purpose systems.
• When an interrupt occurs, the system needs to save the current context of the process
running on the CPU so that it can restore that context when its processing is done, essentially
suspending the process and then resuming it.
• Context is represented on the PCB.
• Switching the CPU to another process requires performing a state save of the current process
and a state restore of a different process. This task is known as a context switch.
• Switching speed varies from machine to machine, depending on the memory speed, the
number of registers that must be copied, and the existence of special instructions (such as a
single instruction to load or store all registers). A typical speed is a few milliseconds
PROCESS CREATION
• During the course of execution, a process may create several new processes.
• The creating process is called a parent process, and the new processes are called the children
of that process.
• Each of these new processes may in turn create other processes, forming a tree of processes.
• When a process creates a child process, that child process will need certain resources (CPU
time, memory, files, I/O devices) to accomplish its task. A child process may be able to obtain
its resources directly from the operating system, or it may be constrained to a subset of the
resources of the parent process.
When a process creates a new process, two possibilities for execution exist:
• The parent continues to execute concurrently with its children.
• The parent waits until some or all of its children have terminated.
There are also two address-space possibilities for the new process:
• The child process is a duplicate of the parent process (it has the same program and data as the
parent).
• The child process has a new program loaded into it.
PROCESS TERMINATION
• A process terminates when it finishes executing its final statement and asks the operating
system to delete it by using the exit() system call.
• At that point, the process may return a status value (typically an integer) to its parent process
(via the wait() system call). All the resources of the process—including physical and virtual
memory, open files, and I/O buffers—are deallocated by the operating system.
• Termination can occur in other circumstances as well. A process can cause the termination of
another process via an appropriate system call (for example, TerminateProcess() inWindows).
PROCESS TERMINATION
• A parent may terminate the execution of one of its children for a variety of reasons, such as these:
– The child has exceeded its usage of some of the resources that it has been allocated.
– The task assigned to the child is no longer required.
– The parent is exiting, and the operating system does not allow a child to continue if its parent terminates.
• In Linux and UNIX systems, we can terminate a process by using the exit() system call. A parent process may
wait for the termination of a child process by using the wait() system call. The wait() system call is passed a
parameter that allows the parent to obtain the exit status of the child
• When a process terminates, its resources are deallocated by the operating system. However, its entry in the
process table must remain there until the parent calls wait(), because the process table contains the process’s
exit status.
• A process that has terminated, but whose parent has not yet called wait(), is known as a zombie process. All
processes transition to this state when they terminate, but generally they exist as zombies only briefly. Once
the parent calls wait(), the process identifier of the zombie process and its entry in the process table are
released.
PROCESS TERMINATION
• If a parent did not invoke wait() and instead terminated, thereby leaving its child processes as
orphans. Linux and UNIX address this scenario by assigning the init process as the new
parent to orphan processes.
• The init process periodically invokes wait(), thereby allowing the exit status of any orphaned
process to be collected and releasing the orphan’s process identifier and process-table entry.