Process Concept
Process Concept
Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Process Concept
1
Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
▪ Execution of program started via GUI mouse clicks, command line entry of its name, etc
▪ New
▪ Ready
▪ Running
▪ Waiting
▪ Terminated
▪ Process state: The state may be new, ready, running, waiting, halted, and so on.
▪ Program counter: PC is a CPU register. CPU uses it when it resumes the execution of a
process. Because the PC stores the address of the last instruction of the process from
where the process was suspended.
▪ CPU registers: CPU registers store the values of different states of the running
process. Every process contains its own registers. A register can hold an instruction, a
storage address, or any kind of data. The most common registers are instruction register
(IR), memory buffer register (MBR, memory data register (MDR), memory address
register (MAR)
▪ CPU-scheduling information: This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
Dr. Mesut ÜNLÜ
Process Control Block (PCB) Dr. Mesut ÜNLÜ
▪ The process model discussed so far has implied that a process is a program that
performs a single thread of execution. For example, when a process is running a word-
processor program, a single thread of instructions is being executed.
▪ This single thread of control allows the process to perform only one task at a time.
Thus, the user can not simultaneously type in characters and run the spell checker.
▪ Most modern operating systems have extended the process concept to allow a process
to have multiple threads of execution and thus to perform more than one task at a time.
o A multithreaded word processor would, for example, assign one thread to manage user input while
another thread runs the spellchecker.
Dr. Mesut ÜNLÜ
Process Scheduling Dr. Mesut ÜNLÜ
▪ As processes enter the system, they are put into a ready queue, where they are ready
and waiting to execute on a CPU’s core This queue is generally stored as a linked list; a
ready-queue header contains pointers to the first PCB in the list, and each PCB includes
a pointer field that points to the next PCB in the ready queue.
▪ Those processes that are blocked by OS exist in the wait queue. It is due to requesting a
process for an I/O device or user input request.
▪ Suppose the process makes an I/O request to a device such as a disk. Since devices run
significantly slower than processors, the process will have to wait for the I/O to become
available. Processes that are waiting for a certain event to occur - such as completion of I/O
- are placed in a wait queue
Scheduling Queues
Dr. Mesut ÜNLÜ
Representation of Process Scheduling Dr. Mesut ÜNLÜ
▪ Switching the CPU to another process by saving the current state of a running
process in PCB. Loading the saved state from PCB for a new process is called
context switching.
▪ It is a complementary part of a multitasking operating system.
▪ Context switching enables all processes to share a single CPU to finish their
execution and store the status of the system’s tasks.
▪ The three different categories of context-switching triggers are as follows.
o Interrupts
o Multitasking
o User/Kernel switch
Dr. Mesut ÜNLÜ
Context Switch Dr. Mesut ÜNLÜ
▪ When CPU switches to another process, the system must save the state of the
old process and load the saved state for the new process via a context switch
▪ Context of a process represented in the PCB
▪ A Context switch time is a period required between two processes (i.e.,
getting a waiting process for execution and sending an executing process to a
waiting state).
o Context-switch time is overhead; the system does no useful work while switching
o Time dependent on hardware support
o Some hardware provides multiple sets of registers per CPU → multiple contexts
loaded at once
Dr. Mesut ÜNLÜ
CPU Switch From Process to Process Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Context Switch Dr. Mesut ÜNLÜ
▪ The following information is stored for later use in PCB when the process is
switched. The context of a process consists:
o Process ID
o Process State
o Pointer
o Priority
o PC
o CPU Registers
o I/O information
o Accounting Information
Dr. Mesut ÜNLÜ
Operations on Processes Dr. Mesut ÜNLÜ
▪ Process Creation
▪ Parent process create children processes, which, in turn create other processes,
forming a tree of processes
▪ Generally, process identified and managed via a process identifier (pid)
▪ Resource sharing options
o Parent and children share all resources
o Children share subset of parent’s resources
o Parent and child share no resources
▪ Execution options
o Parent and children execute concurrently
o Parent waits until children terminate
Dr. Mesut ÜNLÜ
Operations on Processes Dr. Mesut ÜNLÜ
▪ Process Creation
▪ Address space
o Child duplicate of parent
o Child has a program loaded into it
▪ UNIX examples
o fork() system call creates new
process
o exec() system call used after a fork()
to replace the process’ memory space
with a new program
Dr. Mesut ÜNLÜ
Operations on Processes Dr. Mesut ÜNLÜ
▪ 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 waiting 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 and
reclaimed by the operating system.
▪ The exit() system call, providing an exit status as a parameter in Unix & Linux.
/* exit with status 1 */
exit(1);
Dr. Mesut ÜNLÜ
Operations on Processes Dr. Mesut ÜNLÜ
▪ Process Termination
▪ Parent may terminate the execution of children processes using the abort()
system call. Some reasons for doing so:
o Child has exceeded allocated resources
o Task assigned to child is no longer required
o The parent is exiting and the operating systems does not allow a child to continue if
its parent terminates
Dr. Mesut ÜNLÜ
Operations on Processes Dr. Mesut ÜNLÜ
▪ Process Termination
▪ Some operating systems do not allow the child to exist if its parent has
terminated. If a process terminates, then all its children must also be terminated.
o Cascading termination: All children, grandchildren, etc. Are terminated.
o The termination is initiated by the operating system.
▪ The parent process may wait for the termination of a child process by using the
wait()system call. The call returns status information and the pid of the terminated
process by → pid = wait(&status);
▪ If no parent waiting (did not invoke wait()) process is a zombie
▪ If parent terminated without invoking wait() , process is an orphan
Dr. Mesut ÜNLÜ
Multiprocess Architecture - Chrome BrowserDr. Mesut ÜNLÜ
▪ Many web browsers ran as single process (some still do). If one web site causes trouble,
entire browser can hang or crash. But, Google Chrome Browser is multiprocess with 3
different types of processes:
o Browser process manages user interface, disk, and network I/O
o Renderer process renders web pages, deals with HTML, Javascript. A new renderer created for each
website opened.
o Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits
o Plug-in process for each type of plug-in
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ