0% found this document useful (0 votes)
4 views39 pages

Process Concept

huhhx

Uploaded by

Soha Aa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views39 pages

Process Concept

huhhx

Uploaded by

Soha Aa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Dr.

Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

Process Concept

Asist.Prof. Mesut ÜNLÜ

1
Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

▪ An operating system executes a variety of programs:


o Batch system – jobs

o Time-shared systems – user programs or tasks


Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

▪ Process: A process is a program in execution; process


execution must progress in a sequential fashion.
▪ A process is sometimes called a job or a task.
▪ The status of the current activity of a process is represented
by the value of the program counter
▪ The memory layout of a process is typically divided into
multiple sections, and these sections include:
o Text
o Data
o Heap
Layout of a process in memory
o Stack
Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

STACK The Stack contains the temporary data, such as


function parameters, returns addresses, and local
variables.

HEAP It is dynamically allocated memory to a process


during its execution time.

DATA It contains the global and static variables.

TEXT It includes the current instructions represented by


the Program Counter. It also represents the contents
of the processor’s registers. Executable codes.
Layout of a process in memory
Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

▪ Program vs. Process


▪ The process is actually a program in running State. But the main difference between
program and process is,
“Every Program which is written in Low or High-level language like (Assembly, C++, and Java, etc.) is
called Program. When CPU executes any program, then it becomes a process.”
▪ Program is a passive entity stored on disk (executable file), process is active
“A process is a program which contains a set of instructions to execute.”

▪ Execution of program started via GUI mouse clicks, command line entry of its name, etc

▪ One program can be several processes

o Consider multiple users executing the same program


Process Concept
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

▪ Operations on the Process


▪ Creation: OS creates the Processes through System calls at a secondary level.
▪ Scheduling: Selecting the process to be executed next is known as scheduling.
▪ Execution: When the process is scheduled for execution. Then, the CPU starts
executing it.
▪ Deletion/killing: Once the process is over, the OS will kill that process.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ Process States: As a process


executes, it changes state
o new: The process is being created

o running: Instructions are being executed

o waiting: The process is waiting for some


event to occur (such as an I/O completion or
reception of a signal)

o ready: The process is waiting to be assigned


to a processor

o terminated: The process has finished


execution
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ New

▪ When a process is created, it exists in


secondary memory. Then, the OS picks up new
that process from the secondary memory
to the main memory to execute it.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ Ready

▪ The ready process exists in the main


memory. It waits for the CPU to be
assigned to it. There may be many
ready
processes present in the ready state.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ Running

▪ Any process in a ready state can be taken


by the OS and assigned to the CPU for
execution through CPU scheduling
running
algorithms.
o If we have only one CPU in our system,
then only one process will be in execution
at a time.

o If we have N number of CPUs in the


system, then N number of processes can
be running simultaneously.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ Waiting

▪ From the Running state, a process can go to


the waiting state, depending upon
Scheduling algorithm (i.e., time quantum)
o The process can request for some I/O device

o Interrupt can occur


waiting
o System Call may invoke

▪ When a process requests an I/O, the OS


blocks the running process and assigns the
CPU to the next processes.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ

▪ Terminated

▪ OS terminates all Processes.

▪ When a process finishes its execution, it terminated

goes to the termination state.

▪ All the context of that process, which exists


in the Process Control Block (PCB) is also
deleted.
Dr. Mesut ÜNLÜ
Process State Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Process Control Block (PCB) Dr. Mesut ÜNLÜ

▪ Each process is represented in the operating system by a


process control block (PCB) - also called a task control block.
PCB is a data structure to store all information about a process.
It contains information about a specific process:
o Process state
o Program counter
o CPU registers
o CPU scheduling information
o Memory-management information
o Accounting information
o I/O status information
Dr. Mesut ÜNLÜ
Process Control Block (PCB) Dr. Mesut ÜNLÜ

▪ 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Ü

▪ Memory-management information: This information may include such items as the


value of the base and limit registers and the page tables, or the segment tables,
depending on the memory system used by the operating system.
▪ Accounting information: This information includes the amount of CPU and real-time
used, time limits, account numbers, job or process numbers, and so on.
▪ I/O status information: This information includes the list of I/O devices allocated to
the process, a list of open files, and so on.
Dr. Mesut ÜNLÜ
Threads 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Ü

▪ The objective of multiprogramming is to have some process running at all times so as to


maximize CPU utilization.
▪ The objective of time sharing is to switch a CPU core among processes so frequently
that users can interact with each program while it is running. To meet these objectives,
the process scheduler selects an available process (possibly from a set of several
available processes) for program execution on a core.
▪ Each CPU core can run one process at a time
▪ For a system with a single CPU core, there will never be more than one
process running at a time, whereas a multicore system can run multiple
processes at one time.
Dr. Mesut ÜNLÜ
Process Scheduling Dr. Mesut ÜNLÜ

▪ The number of processes currently in memory is known as the degree of


multiprogramming.
▪ Processes can be described as either I/O bound or CPU bound.
o An I/O-bound process spends more time doing I/O than doing computations.
These operations involve interactions with external resources such as databases, file
systems, network requests, and more. I/O-bound tasks typically involve reading or
writing data from or to external sources.
o A CPU-bound process, in contrast, generates I/O requests infrequently, using
more of its time doing computations. These tasks involve complex calculations, data
processing, and algorithmic operations that heavily utilize the CPU.
Dr. Mesut ÜNLÜ
Scheduling Queues 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.

The ready queue


Dr. Mesut ÜNLÜ
Scheduling Queues Dr. Mesut ÜNLÜ

▪ 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

The wait queue


Dr. Mesut ÜNLÜ
Scheduling Queues Dr. Mesut ÜNLÜ

▪ Suspended Queue: It contains processes, temporarily kicked out of main memory.


▪ OS maintains all PCBs of each process in their scheduling Queues. It uses different process
scheduling algorithms to manage each queue.
▪ Processes migrate among the various queues.

Scheduling Queues
Dr. Mesut ÜNLÜ
Representation of Process Scheduling Dr. Mesut ÜNLÜ

▪ Queueing diagram represents queues, resources, flows.


▪ When a process is created, then it enters into the system as a running state. Not running
processes are kept in a waiting queue for their turn to execute. Dispatcher is used for this
purpose.
▪ The process could issue an I/O request and then be
placed in an I/O wait queue.
▪ The process could create a new child process and then
be placed in a wait queue while it awaits the child’s
termination.
▪ The process could be removed forcibly from the core,
as a result of an interrupt or having its time slice
expire, and be put back in the ready queue.

Queueing-diagram representation of process scheduling


Dr. Mesut ÜNLÜ
CPU Scheduling Dr. Mesut ÜNLÜ

▪ CPU Schedulers are also known as CPU Dispatchers. It is a module or


program that provides control of the CPU to the process.
▪ The role of the CPU scheduler is to select from among the processes that are in
the ready queue and allocate a CPU core to one of them.
▪ The Dispatcher executes each context switching.
▪ Dispatch latency is the time that is needed by the CPU scheduler to stop one
process and start another.
Dr. Mesut ÜNLÜ
Schedulers Dr. Mesut ÜNLÜ

▪ Short-term scheduler (CPU scheduler) selects which process should be


executed next and allocates CPU
o Sometimes the only scheduler in a system
o Short-term scheduler is invoked frequently (milliseconds) (must be fast)
▪ Long-term scheduler (Job scheduler) selects which processes should be
brought into the ready queue
o Long-term scheduler is invoked infrequently (seconds, minutes) (may be slow)
o The long-term scheduler controls the degree of multiprogramming
o Long-term scheduler strives for good process mix
Dr. Mesut ÜNLÜ
Schedulers Dr. Mesut ÜNLÜ

▪ Medium-term scheduler can be added if the degree of multiple programming


needs to decrease
o Remove process from memory, store on disk, bring back in from disk to continue execution:
swapping
Dr. Mesut ÜNLÜ
Context Switch 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Ü

▪ The system must provide mechanisms for:


o process creation,
o process termination,
▪ 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.
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Ü

A tree of processes on a typical Linux system


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Ü

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy