SlideShare a Scribd company logo
1 of 62
UNIT-1-PROCESS MANAGEMENT
PROCESS CONCEPT
PROCESS:
• Process is the program in execution. Process is the unit of work.
• The execution of a process must progress in a sequential fashion.
• A process is defined as an entity which represents the basic unit of work to be
implemented in the system. A process is a dynamic instance of a computer program.
• When a program is loaded into the memory and it becomes a process, it can be
divided into four sections ─ stack, heap, text and data.
Process stack- The process Stack contains the temporary data such as
method/function parameters, return address and local variables.
Heap- This is dynamically allocated memory to a process during its run time
Text- This includes the current activity represented by the value of Program
Counter and the contents of the processor's registers.
Data section: contains global and static variables
Process in Memory
Process states:
• Process changes its state during execution.
• The current activity of that process is determined as state of a
process.
• Each process may be in one of the following states:
New: the new process is created
Running: Instructions are executed
Waiting: the process is waiting for some event to occur.
Ready: the process is waiting to be assigned to a processor
Terminated: the process has finished execution.
Process states
Process Control Block
• Each process has its own process control block(PCB). It contains the entire information
about a process.
• It is also called as task control block. A Process Control Block is a data structure
maintained by the Operating System for every process.
• The PCB is identified by an integer process ID (PID). A PCB keeps all the information
needed to keep track of a process as listed below.
Process state-The current state of the process i.e., whether it is ready, running,
waiting, or whatever.
Process privileges-This is required to allow/disallow access to system resources.
Process ID-Unique identification for each of the process in the operating system.
Pointer-A pointer to parent process.
Program counter- the address of the next instruction to be executed.
CPU registers- where process need to be stored for execution (running state).
Depending on the computer architecture, the registers vary in the number and type.
CPU scheduling information-includes process priority, pointers to scheduling queues,
and other scheduling parameters.
 Memory management information- includes base and limit registers, the page
tables, or the segment tables.
 Accounting information- includes the amount of CPU, time limits, account
numbers, job or process numbers.
 Status information- includes the list of I/O devices, a list of open files.
• The PCB is maintained for a process throughout its
lifetime, and is deleted once the process terminates.
PROCESS CONTROL BLOCK
Process scheduling
Process scheduling:
• The objective of multiprogramming is to have some process running at all times,
so as to maximize CPU utilization.
• The process scheduling is the activity of the process manager that handles the
removal of the running process from the CPU and the selection of another
process on the basis of a particular strategy.
• OS maintains all PCB’s in process scheduling queues.
• Scheduling queues:
1. Job queue- new process that enter the system are put into a job queue
2. Ready queue- the processes that are residing in the main memory and are
ready and waiting to execute are kept on the queue
3. Device queue- the processes that are waiting for an I/O device is kept in a
device queue.
• A new process is initially put in the ready queue.
• It waits in the ready queue until it is selected for the execution(or
dispatched)
• Once the process is given with the CPU and is executing , the following
events occur,
The process issue an I/O request, and then be placed in an I/O queue.
The process creates a new sub-process and wait for its termination.
The processes are removed forcibly from the CPU due to an interrupt,
and it is put back in the ready queue.
• The OS can use different policies to manage each queue (FIFO, SJF, Round
robin, priority etc.)
Two state process model:
• Two state process model refers to running and non-running states.
Running- when a new process is created, it enters into the system as in the running
state.
Not running- Processes that are not running are kept in queue, waiting for their
turn to execute.
• Each entry in the queue is the pointer to a particular process. Queue is
implemented by using linked list.
• Dispatcher- when a process is interrupted, that process is transferred in the waiting
queue. If the process has completed or aborted, the process is discarded. In either
case, the dispatcher then selects a process from queue to execute.
Process scheduling
Process scheduler:
• A process migrates between the scheduling queues throughout its lifetime.
• The selection process is carried out by the appropriate scheduler.
• There are three different types of schedulers. They are
1. Long term scheduler or job scheduler
2. Short term scheduler or CPU scheduler
3. Medium term scheduler
Long term and short term scheduler
Long term scheduler:
• It is also called as job scheduler
• It selects processes from the pool and loads them into main memory for execution.
• It is invoked very infrequently.
• It controls the degree of multiprogramming
Short term scheduler:
• It is also called as CPU scheduler.
• It selects processes from among the processes that are ready to execute, and allocates the
CPU to one of them.
• It is invoked very frequently.
• Processes can be described as either I/O bound or CPU bound.
An I/O bound process spends more time on I/O operation than it spends doing
computation.
A CPU bound process spends more time on doing computation than an I/O bound process.
I/O requests is generated infrequently.
Medium term scheduler:
• Medium term scheduling is a part of swapping.
• It removes process from main memory and thus reduces the degree of
multiprogramming.
• Medium-term scheduler is in-charge of handling the swapped out
processes.
• A running process may become suspended if it makes an I/O request. A
suspended process cannot make any progress towards completion.
• In this condition, to remove process from memory and make space for
other processes, the suspended process is moved to secondary storage.
This process is called swapping. The process can be reintroduced into main
memory and its execution can be continued where it left off.
Differences between short term, long term and medium term
scheduler:
Context switch:
• A context is the content of a CPU’s registers and program counter at
any point of time.
• 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.
• A register is a small and very fast memory inside the CPU, that is used
to speed the execution of a computer programs by providing quick
access to commonly used values.
• Context switch can occur only in kernel mode.
Operations on processes
1. Process creation:
• During the process execution, a process may create several new processes.
• The creating process is called parent process. The new process is called
child process.
• Two possibilities exist in terms of execution:
1. The parent process continues to execute concurrently with its children.
2. The parent process waits until some or all of its children have
terminated.
• Two possibilities in terms of address space:
1. The child process is a duplicate of the parent process.
2. The child process has a program loaded into it.
• A new process is created by the fork system call.
2. Process termination:
• A process execution is terminated when it finishes executing its final
statement and ask the OS to delete it by using the exit system call.
• The process may return output data to its parent process by calling the
wait system call.
• A parent process may terminate the execution of one of its child process
due to,
1. The child process has exceeded its usage of some of the resources that it
has been allocated.
2. The task assigned to the child process is no longer required.
3. If the parent process is exiting, the OS does not allow a child to continue.
4. If a process terminates normally or abnormally, then all its child
processes must also be terminated. This phenomenon, referred to as
cascading termination.
3.Cooperating processes:
• The concurrent processes executing in the OS may be either
independent processes or cooperating processes.
• A process is independent if it cannot affect or be affected by the
other processes executing in the system.
• A process is cooperating if it can affect or be affected by the other
processes executing in the system.
• The benefits of cooperating processes are
1. Information sharing
2. Computation speedup
3. Modularity
4. Convenience
Interprocess communication
• IPC provides a mechanism to allow processes to communicate and to
synchronize their actions.
• This communication could involve a process letting another process
know that some event has occurred or the transferring of data from
one process to another.
• Two models
Shared memory model
Message passing system
Synchronization in Interprocess Communication
• Synchronization is a necessary part of interprocess communication.
• It is either provided by the interprocess control mechanism or handled by the
communicating processes.
• Some of the methods to provide synchronization are as follows −
Semaphore-A semaphore is a variable that controls the access to a common
resource by multiple processes. The two types of semaphores are binary
semaphores and counting semaphores.
Mutual Exclusion-Mutual exclusion requires that only one process thread can
enter the critical section at a time. This is useful for synchronization and also
prevents race conditions.
Barrier-A barrier does not allow individual processes to proceed until all the
processes reach it. Many parallel languages and collective routines impose barriers.
Spinlock-This is a type of lock. The processes trying to acquire this lock wait in a
loop while checking if the lock is available or not. This is known as busy waiting
because the process is not doing any useful operation even though it is active.
Interprocess Communication:
Shared memory model:
• Processes shares a memory with other process.
Example –Producer Consumer Problem:
• There are two processes: Producer and Consumer.
• The producer produces some items and the Consumer consumes that
item. The two processes share a common space or memory location
known as a buffer where the item produced by the Producer is stored
and from which the Consumer consumes the item if needed.
• To allow producer and consumer processes to run concurrently, a
buffer of items are available that can be filled by the producer and
emptied by the consumer.
• Unbounded-buffer: places no practical limit on the size of the buffer.
• Bounded buffer: assumes that there is a fixed buffer size.
• There are two versions of this problem: the first one is known as the unbounded
buffer problem in which the Producer can keep on producing items and there is
no limit on the size of the buffer.
• The second one is known as the bounded buffer problem in which the Producer
can produce up to a certain number of items before it starts waiting for
Consumer to consume it.
• Bounded buffer problem-First, the Producer and the Consumer will share some
common memory, then the producer will start producing items. If the total
produced item is equal to the size of the buffer, the producer will wait to get it
consumed by the Consumer.
• Similarly, the consumer will first check for the availability of the item. If no item is
available, the Consumer will wait for the Producer to produce it. If there are
items available, Consumer will consume them.
Shared data:
Producer Process Code
Consumer Process Code
• In the above code, the Producer will start producing again when the
(free_index+1) mod buff_max will be free.
• if it not free, this implies that there are still items that can be
consumed by the Consumer so there is no need to produce more.
• Similarly, if free index and full index point to the same index, this
implies that there are no items to consume.
ii) Messaging Passing Method
• In this method, processes communicate with each other by message passing.
• A communication link must exist between them.
• If two processes p1 and p2 want to communicate with each other, they proceed as
follows:
Establish a communication link (if a link already exists, no need to establish it again.)
Start exchanging messages using basic primitives.
We need at least two primitives:
– send(message, destination) or send(message)
– receive(message, host) or receive(message)
• The message size can be of fixed size or of variable size.
• If it is of fixed size, it is easy for an OS designer but complicated for a
programmer and if it is of variable size then it is easy for a
programmer but complicated for the OS designer.
• A standard message can have two parts: header and body.
• The header part is used for storing message type, destination id,
source id, message length, and control information.
• The control information contains information like what to do if runs
out of buffer space, sequence number, priority. Generally, message is
sent using FIFO style.
• There are several methods for logically implementing a link and the
operations.
 Direct or indirect communication
 Symmetric or asymmetric communication
 Automatic or explicit buffering
 Send by copy or send by reference
 Fixed sized or variable sized messages.
• Naming- processes that want to communicate must have a way to
refer to each other.
Direct and Indirect Communication link
• While implementing the link, there are some questions that need to be kept in
mind like :
1. How are links established?
2. Can a link be associated with more than two processes?
3. How many links can there be between every pair of communicating processes?
4. What is the capacity of a link? Is the size of a message that the link can
accommodate fixed or variable?
5. Is a link unidirectional or bi-directional?
• A link has some capacity that determines the number of messages that can
reside in it temporarily for which every link has a queue associated with it
which can be of zero capacity, bounded capacity, or unbounded capacity.
• In zero capacity, the sender waits until the receiver informs the sender that
it has received the message.
• In non-zero capacity(bounded/unbounded) cases, a process does not know
whether a message has been received or not after the send operation.
• For this, the sender must communicate with the receiver explicitly.
Implementation of the link depends on the situation, it can be either a
direct communication link or an in-directed communication link.
• Direct Communication are implemented when the processes use a specific
process identifier for the communication
• In-direct Communication is done via a shared mailbox (port), which
consists of a queue of messages. The sender keeps the message in mailbox
and the receiver picks them up.
Direct communication:
• Each process that wants to communicate must explicitly name the recipient or sender of the
communication
• A communication link has the following properties
1. A link is established automatically between every pair of the processes that want to
communicate. The processes need to know only each others identity to communicate.
2. A link is associated with exactly two processes.
3. Exactly one link exists between each pair of processes.
• There are two ways of addressing namely
• Symmetry in addressing- the sender and receive primitives are defined as
Send(A, message)-send a message to process A
Receive(B, message)-receive a message from B
• Asymmetry in addressing- the sender and receive primitives are defined as
Send(A, message)-send a message to process A
Receive(id, message)-receive a message from any process with the corresponding id.
In-direct Communication
• With indirect communication, the messages are sent to and received from mailboxes, or ports.
• The sender and receive primitives are defined as
Send(M, message)-send a message to mailbox M
Receive(M, message)-receive a message from mailbox M.
• The communication link has the following properties
1. A link is established between a pair of processes only if both members of the pair have a shared
mailbox.
2. A link is may be associated with more than two processes.
3. A number of different links may exists between each pair of communicating processes, with each
link corresponding to one mailbox.
Buffering:
• A link has some capacity that determines the number of messages that can reside in it
temporarily.
• Zero capacity- queue length of maximum is 0. no messages is waiting in a queue. The
sender must wait until the recipient receives the messages.
• Bounded capacity- the queue has finite length n. thus at most n messages can reside in it.
• Unbounded capacity- the queue has potentially infinite length. Thus any number of
messages can wait in it.
Synchronization:
• Message passing may be either blocking or non blocking.
• Blocking send- the sender blocks itself till the message sent by it is
receive by the receiver.
• Non- Blocking send- the sender does not block itself after sending the
messages but continues with its normal operation.
• Blocking receive- the receiver block itself until it receives the
message.
• Non- Blocking receive- the receiver does not block itself.
Threads
Threads- Overview:
• A thread is the basic unit of CPU utilization. A thread provides away to improve
application performance through parallelism.
• It is sometimes called as light weight process.
• It is the flow of execution through the process code, thread ID, a program
counter, a register set and a stack.
• Each thread belongs to any of one process and no thread can exist outside a
process.
• It share with other threads belonging to the same process its code section, data
section, and resources such as open files and signals.
• A traditional or heavy weight process has a single thread of control.
• If the process has multiple threads of control, it can do more than one task at a
time.
Process Threads
Process is a heavy weight or resource
intensive
Thread is light weight taking lesser
resources than a process.
Process switching needs interaction with
the OS
Thread switching does not need
interaction with the OS
In multiprocessing environments each
process executes the same code but has
its own memory and file resources
All threads can share same set of open
files, child processes.
If one process is blocked, then no other
process can execute until the first
process is unblocked
When one thread is blocked and waiting,
second thread in the same task can run.
Multiple processes without using the
thread use more resources
Multiple threaded process uses fewer
resources
In multiple process, each process
operates independently of the others.
One thread can read, write or change
another thread’s data.
Benefits of Multithreads
• Enhanced throughput of the system: When the process is split into many
threads, and each thread is treated as a job, the number of jobs done in the unit
time increases. That is why the throughput of the system also increases.
• Effective Utilization of Multiprocessor system: When you have more than one
thread in one process, you can schedule more than one thread in more than one
processor.
• Faster context switch: The context switching period between threads is less than
the process context switching. The process context switch means more overhead
for the CPU.
• Responsiveness: When the process is split into several threads, and when a
thread completes its execution, that process can be responded to as soon as
possible.
• Communication: Multiple-thread communication is simple because the threads
share the same address space, while in process, we adopt just a few exclusive
communication strategies for communication between two processes.
• Resource sharing: Resources can be shared between all threads within a process,
such as code, data, and files. Note: The stack and register cannot be shared
between threads. There is a stack and register for each thread.
Need of Thread:
• It takes less time to create a new thread in an existing process than to
create a new process.
• Threads can share the common data, they do not need to use Inter-
Process communication.
• Context switching is faster when working with threads.
• It takes less time to terminate a thread than a process.
Types of Threads
• In the Operating system, there are two types of threads.
Kernel level thread
User-level thread
User-level thread
• The OS does not recognize the user-level thread.
• User threads can be easily implemented by the user. If a user performs a user-level thread blocking
operation, the whole process is blocked.
• The kernel level thread does not know nothing about the user level thread. The kernel-level thread
manages user-level threads as if they are single-threaded processes.
Advantages of User-level threads
• The user threads can be easily implemented than the kernel thread.
• User-level threads can be applied to such types of OS that do not support threads at the kernel-level.
• It is faster and efficient.
• Context switch time is shorter than the kernel-level threads.
• It does not require modifications of the operating system.
• User-level threads representation is very simple. The register, PC, stack, and mini thread control
blocks are stored in the address space of the user-level process.
• It is simple to create, switch, and synchronize threads without the intervention of the process.
Disadvantages of User-level threads
• User-level threads lack coordination between the thread and the kernel.
• If a thread causes a page fault, the entire process is blocked.
Kernel level thread
• The kernel thread recognizes the operating system.
• There is a thread control block and process control block in the system for each thread
and process in the kernel-level thread.
• The kernel-level thread is implemented by the operating system. The kernel knows about
all the threads and manages them.
• The kernel-level thread offers a system call to create and manage the threads from user-
space. The implementation of kernel threads is more difficult than the user thread.
• Context switch time is longer in the kernel thread.
Advantages of Kernel-level threads
• The kernel-level thread is fully aware of all threads.
• The scheduler may decide to spend more CPU time in the process of
threads being large numerical.
• The kernel-level thread is good for those applications that block the
frequency.
Disadvantages of Kernel-level threads
• The kernel thread manages and schedules all threads.
• The implementation of kernel threads is difficult than the user thread.
• The kernel-level thread is slower than user-level threads.
Multicore programming
• Multicore programming helps to create concurrent systems for deployment on multicore
processor and multiprocessor systems.
• A multicore processor system is basically a single processor with multiple execution cores
in one chip.
• A Field-Programmable Gate Array (FPGA) is might be included in a multiprocessor
system. A FPGA is an integrated circuit containing an array of programmable logic blocks
and a hierarchy of reconfigurable interconnects.
• Input data is processed by to produce outputs. It can be a processor in a multicore or
multiprocessor system, or a FPGA.
Advantages:
• Multicore and FPGA processing helps to increase the performance of an embedded
system.
• Also helps to achieve scalability, so the system can take advantage of increasing numbers
of cores and FPGA processing power over time.
• Concurrent systems that we create using multicore programming have multiple tasks
executing in parallel. This is known as concurrent execution. When multiple parallel tasks
are executed by a processor, it is known as multitasking.
Disadvantages:
• A CPU scheduler, handles the tasks that execute in parallel. The CPU implements tasks
using OS threads. So that tasks can have some data transfer between them, such as data
transfer between a data acquisition module and controller for the system. Data transfer
occurs when there is a data dependency.
Multicore programming
Multithreading models in OS
Multithreading models:
• Multithreading allows the application to divide its task into individual threads.
• In multi-threads, the same process or task can be done by the number of threads.
• With the use of multithreading, multitasking can be achieved.
• The main drawback of single threading systems is that only one task can be performed at a
time, so to overcome the drawback of this single threading, there is multithreading that
allows multiple tasks to be performed.
There exists three established multithreading models
Many to one multithreading model
One to one multithreading model
Many to Many multithreading models
Many to one multithreading model:
• The many to one model maps many user levels threads
to one kernel thread.
• This type of relationship facilitates an effective context-
switching environment, easily implemented even on the
simple kernel with no thread support.
Disadvantage
• since there is only one kernel-level thread schedule at
any given time, this model cannot take advantage of
the hardware acceleration offered by multithreaded
processes or multi-processor systems.
• In this, all the thread management is done in the user
space. If blocking comes, this model blocks the whole
system.
One to one multithreading model
• The one-to-one model maps a single user-level
thread to a single kernel-level thread.
• This type of relationship facilitates the running of
multiple threads in parallel.
• The generation of every new user thread must
include creating a corresponding kernel thread
causing an overhead, which can hinder the
performance of the parent process.
• Windows series and Linux operating systems try to
tackle this problem by limiting the growth of the
thread count.
Many to Many Model multithreading model
• In this type of model, there are several user-level threads
and several kernel-level threads.
• The number of kernel threads created depends upon a
particular application.
• The developer can create as many threads at both levels but
may not be the same.
• The many to many model is a compromise between the
other two models.
• In this model, if any thread makes a blocking system call, the
kernel can schedule another thread for execution. Also, with
the introduction of multiple threads, complexity is not
present as in the previous models.
• Though this model allows the creation of multiple kernel
threads, true concurrency cannot be achieved by this
model. This is because the kernel can schedule only one
process at a time.
Threading issues:
1. Fork and exec system call:
• Fork system call is used to create a separate duplicate process.
• If one thread in a program calls fork system calls, then
 Creating a new process that duplicates all threads.
 Creating a new process that duplicates only one thread that invoked
the fork.
• If a thread invokes Exec system call, the program specified in the
parameter to exec will replace the entire process including all
threads.
Factors for Differentiation fork() exec()
Invoking fork() creates a new duplicate child
process of the process that invoked
fork()
exec() replaces a process that
invokes it with a new process
provided in its parameter.
Process id The child process and parent
process have unique process id.
The new process and the replaced
process have the same process id.
Execution The parent and child process start
simultaneous execution from the
instruction just after fork().
The currently running process is
terminated and the exec() start
execution of the new process from
its entry point.
Arguments No arguments are passed to fork()
system call.
Basically, three or more arguments
are passed to the exec() system call.
Format Pid=fork(); exec(cont char *filename, char*
const argv[], char* const envp[])
2. Cancellation:
• Thread cancellation means terminating a thread before it has completed.
• A thread that is to be cancelled is referred to as target thread.
• Asynchronous cancellation- one thread immediately terminates the target thread.
• Deferred cancellation- the target thread can periodic check if it should terminate,
allowing an opportunity to terminate itself in an orderly fashion.
3. Signal handling:
• A signal is used to notify a process that a particular event has occurred.
• A signal may be received either synchronous or asynchronous .
• Every signal may be handled by one of the two handlers.
• Default signal handler- run by the kernel.
• User defined handler-run by the user defined functions.
• Delivering the signal is more complicated in multithreading program.
4. Thread pools:
• When creating a separate thread, multithread server has some potential
problems.
• Amount of time required to create the thread prior servicing the request.
• Discarding the thread once it completes the task.
• There is no bound on the number of threads concurrently active in the
system.
• Create number of threads at process startup and place them into a pool,
where they sit and wait for work.
• When a server receives a request, it awakens a thread from this pool, if one
is available.
• If thread completes its service, it returns to the pool.

More Related Content

Similar to UNIT I-Processes.pptx

opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxssuser3dfcef
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process ConceptsMukesh Chinta
 
Processes
ProcessesProcesses
ProcessesRaviRaj339
 
UNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdfUNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdfAyushSharma651966
 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdfRakibul Rakib
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingVaibhav Khanna
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptxDivyaKS18
 
Operating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringOperating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringYogesh Santhan
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfnikhil287188
 
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptxCPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptxTSha7
 
In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .nathansel1
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdfHikaTariku
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentationchnrketan
 
CSI-503 - 3. Process Scheduling
CSI-503 - 3. Process SchedulingCSI-503 - 3. Process Scheduling
CSI-503 - 3. Process Schedulingghayour abbas
 
Lecture5
Lecture5Lecture5
Lecture5Ali Shah
 
Operating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfOperating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfFahanaAbdulVahab
 

Similar to UNIT I-Processes.pptx (20)

Process Management
Process ManagementProcess Management
Process Management
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptx
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Process management1
Process management1Process management1
Process management1
 
Processes
ProcessesProcesses
Processes
 
UNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdfUNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdf
 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdf
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of scheduling
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
Operating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringOperating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - Engineering
 
Ch03- PROCESSES.ppt
Ch03- PROCESSES.pptCh03- PROCESSES.ppt
Ch03- PROCESSES.ppt
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdf
 
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptxCPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
 
In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
 
CSI-503 - 3. Process Scheduling
CSI-503 - 3. Process SchedulingCSI-503 - 3. Process Scheduling
CSI-503 - 3. Process Scheduling
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfOperating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdf
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerAnamika Sarkar
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoĂŁo Esperancinha
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 

Recently uploaded (20)

young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 

UNIT I-Processes.pptx

  • 3. PROCESS: • Process is the program in execution. Process is the unit of work. • The execution of a process must progress in a sequential fashion. • A process is defined as an entity which represents the basic unit of work to be implemented in the system. A process is a dynamic instance of a computer program. • When a program is loaded into the memory and it becomes a process, it can be divided into four sections ─ stack, heap, text and data. Process stack- The process Stack contains the temporary data such as method/function parameters, return address and local variables. Heap- This is dynamically allocated memory to a process during its run time Text- This includes the current activity represented by the value of Program Counter and the contents of the processor's registers. Data section: contains global and static variables
  • 5. Process states: • Process changes its state during execution. • The current activity of that process is determined as state of a process. • Each process may be in one of the following states: New: the new process is created Running: Instructions are executed Waiting: the process is waiting for some event to occur. Ready: the process is waiting to be assigned to a processor Terminated: the process has finished execution.
  • 7. Process Control Block • Each process has its own process control block(PCB). It contains the entire information about a process. • It is also called as task control block. A Process Control Block is a data structure maintained by the Operating System for every process. • The PCB is identified by an integer process ID (PID). A PCB keeps all the information needed to keep track of a process as listed below. Process state-The current state of the process i.e., whether it is ready, running, waiting, or whatever. Process privileges-This is required to allow/disallow access to system resources. Process ID-Unique identification for each of the process in the operating system. Pointer-A pointer to parent process. Program counter- the address of the next instruction to be executed. CPU registers- where process need to be stored for execution (running state). Depending on the computer architecture, the registers vary in the number and type. CPU scheduling information-includes process priority, pointers to scheduling queues, and other scheduling parameters.
  • 8.  Memory management information- includes base and limit registers, the page tables, or the segment tables.  Accounting information- includes the amount of CPU, time limits, account numbers, job or process numbers.  Status information- includes the list of I/O devices, a list of open files. • The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates. PROCESS CONTROL BLOCK
  • 10. Process scheduling: • The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization. • The process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process on the basis of a particular strategy. • OS maintains all PCB’s in process scheduling queues. • Scheduling queues: 1. Job queue- new process that enter the system are put into a job queue 2. Ready queue- the processes that are residing in the main memory and are ready and waiting to execute are kept on the queue 3. Device queue- the processes that are waiting for an I/O device is kept in a device queue.
  • 11. • A new process is initially put in the ready queue. • It waits in the ready queue until it is selected for the execution(or dispatched) • Once the process is given with the CPU and is executing , the following events occur, The process issue an I/O request, and then be placed in an I/O queue. The process creates a new sub-process and wait for its termination. The processes are removed forcibly from the CPU due to an interrupt, and it is put back in the ready queue. • The OS can use different policies to manage each queue (FIFO, SJF, Round robin, priority etc.)
  • 12. Two state process model: • Two state process model refers to running and non-running states. Running- when a new process is created, it enters into the system as in the running state. Not running- Processes that are not running are kept in queue, waiting for their turn to execute. • Each entry in the queue is the pointer to a particular process. Queue is implemented by using linked list. • Dispatcher- when a process is interrupted, that process is transferred in the waiting queue. If the process has completed or aborted, the process is discarded. In either case, the dispatcher then selects a process from queue to execute.
  • 14. Process scheduler: • A process migrates between the scheduling queues throughout its lifetime. • The selection process is carried out by the appropriate scheduler. • There are three different types of schedulers. They are 1. Long term scheduler or job scheduler 2. Short term scheduler or CPU scheduler 3. Medium term scheduler
  • 15. Long term and short term scheduler
  • 16. Long term scheduler: • It is also called as job scheduler • It selects processes from the pool and loads them into main memory for execution. • It is invoked very infrequently. • It controls the degree of multiprogramming Short term scheduler: • It is also called as CPU scheduler. • It selects processes from among the processes that are ready to execute, and allocates the CPU to one of them. • It is invoked very frequently. • Processes can be described as either I/O bound or CPU bound. An I/O bound process spends more time on I/O operation than it spends doing computation. A CPU bound process spends more time on doing computation than an I/O bound process. I/O requests is generated infrequently.
  • 17. Medium term scheduler: • Medium term scheduling is a part of swapping. • It removes process from main memory and thus reduces the degree of multiprogramming. • Medium-term scheduler is in-charge of handling the swapped out processes. • A running process may become suspended if it makes an I/O request. A suspended process cannot make any progress towards completion. • In this condition, to remove process from memory and make space for other processes, the suspended process is moved to secondary storage. This process is called swapping. The process can be reintroduced into main memory and its execution can be continued where it left off.
  • 18. Differences between short term, long term and medium term scheduler:
  • 19. Context switch: • A context is the content of a CPU’s registers and program counter at any point of time. • 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. • A register is a small and very fast memory inside the CPU, that is used to speed the execution of a computer programs by providing quick access to commonly used values. • Context switch can occur only in kernel mode.
  • 21. 1. Process creation: • During the process execution, a process may create several new processes. • The creating process is called parent process. The new process is called child process. • Two possibilities exist in terms of execution: 1. The parent process continues to execute concurrently with its children. 2. The parent process waits until some or all of its children have terminated. • Two possibilities in terms of address space: 1. The child process is a duplicate of the parent process. 2. The child process has a program loaded into it. • A new process is created by the fork system call.
  • 22. 2. Process termination: • A process execution is terminated when it finishes executing its final statement and ask the OS to delete it by using the exit system call. • The process may return output data to its parent process by calling the wait system call. • A parent process may terminate the execution of one of its child process due to, 1. The child process has exceeded its usage of some of the resources that it has been allocated. 2. The task assigned to the child process is no longer required. 3. If the parent process is exiting, the OS does not allow a child to continue. 4. If a process terminates normally or abnormally, then all its child processes must also be terminated. This phenomenon, referred to as cascading termination.
  • 23. 3.Cooperating processes: • The concurrent processes executing in the OS may be either independent processes or cooperating processes. • A process is independent if it cannot affect or be affected by the other processes executing in the system. • A process is cooperating if it can affect or be affected by the other processes executing in the system. • The benefits of cooperating processes are 1. Information sharing 2. Computation speedup 3. Modularity 4. Convenience
  • 25. • IPC provides a mechanism to allow processes to communicate and to synchronize their actions. • This communication could involve a process letting another process know that some event has occurred or the transferring of data from one process to another. • Two models Shared memory model Message passing system
  • 26. Synchronization in Interprocess Communication • Synchronization is a necessary part of interprocess communication. • It is either provided by the interprocess control mechanism or handled by the communicating processes. • Some of the methods to provide synchronization are as follows − Semaphore-A semaphore is a variable that controls the access to a common resource by multiple processes. The two types of semaphores are binary semaphores and counting semaphores. Mutual Exclusion-Mutual exclusion requires that only one process thread can enter the critical section at a time. This is useful for synchronization and also prevents race conditions. Barrier-A barrier does not allow individual processes to proceed until all the processes reach it. Many parallel languages and collective routines impose barriers. Spinlock-This is a type of lock. The processes trying to acquire this lock wait in a loop while checking if the lock is available or not. This is known as busy waiting because the process is not doing any useful operation even though it is active.
  • 28. Shared memory model: • Processes shares a memory with other process. Example –Producer Consumer Problem: • There are two processes: Producer and Consumer. • The producer produces some items and the Consumer consumes that item. The two processes share a common space or memory location known as a buffer where the item produced by the Producer is stored and from which the Consumer consumes the item if needed. • To allow producer and consumer processes to run concurrently, a buffer of items are available that can be filled by the producer and emptied by the consumer. • Unbounded-buffer: places no practical limit on the size of the buffer. • Bounded buffer: assumes that there is a fixed buffer size.
  • 29. • There are two versions of this problem: the first one is known as the unbounded buffer problem in which the Producer can keep on producing items and there is no limit on the size of the buffer. • The second one is known as the bounded buffer problem in which the Producer can produce up to a certain number of items before it starts waiting for Consumer to consume it. • Bounded buffer problem-First, the Producer and the Consumer will share some common memory, then the producer will start producing items. If the total produced item is equal to the size of the buffer, the producer will wait to get it consumed by the Consumer. • Similarly, the consumer will first check for the availability of the item. If no item is available, the Consumer will wait for the Producer to produce it. If there are items available, Consumer will consume them.
  • 30. Shared data: Producer Process Code Consumer Process Code
  • 31. • In the above code, the Producer will start producing again when the (free_index+1) mod buff_max will be free. • if it not free, this implies that there are still items that can be consumed by the Consumer so there is no need to produce more. • Similarly, if free index and full index point to the same index, this implies that there are no items to consume.
  • 32. ii) Messaging Passing Method • In this method, processes communicate with each other by message passing. • A communication link must exist between them. • If two processes p1 and p2 want to communicate with each other, they proceed as follows: Establish a communication link (if a link already exists, no need to establish it again.) Start exchanging messages using basic primitives. We need at least two primitives: – send(message, destination) or send(message) – receive(message, host) or receive(message)
  • 33. • The message size can be of fixed size or of variable size. • If it is of fixed size, it is easy for an OS designer but complicated for a programmer and if it is of variable size then it is easy for a programmer but complicated for the OS designer. • A standard message can have two parts: header and body. • The header part is used for storing message type, destination id, source id, message length, and control information. • The control information contains information like what to do if runs out of buffer space, sequence number, priority. Generally, message is sent using FIFO style.
  • 34. • There are several methods for logically implementing a link and the operations.  Direct or indirect communication  Symmetric or asymmetric communication  Automatic or explicit buffering  Send by copy or send by reference  Fixed sized or variable sized messages. • Naming- processes that want to communicate must have a way to refer to each other.
  • 35. Direct and Indirect Communication link • While implementing the link, there are some questions that need to be kept in mind like : 1. How are links established? 2. Can a link be associated with more than two processes? 3. How many links can there be between every pair of communicating processes? 4. What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? 5. Is a link unidirectional or bi-directional?
  • 36. • A link has some capacity that determines the number of messages that can reside in it temporarily for which every link has a queue associated with it which can be of zero capacity, bounded capacity, or unbounded capacity. • In zero capacity, the sender waits until the receiver informs the sender that it has received the message. • In non-zero capacity(bounded/unbounded) cases, a process does not know whether a message has been received or not after the send operation. • For this, the sender must communicate with the receiver explicitly. Implementation of the link depends on the situation, it can be either a direct communication link or an in-directed communication link. • Direct Communication are implemented when the processes use a specific process identifier for the communication • In-direct Communication is done via a shared mailbox (port), which consists of a queue of messages. The sender keeps the message in mailbox and the receiver picks them up.
  • 37. Direct communication: • Each process that wants to communicate must explicitly name the recipient or sender of the communication • A communication link has the following properties 1. A link is established automatically between every pair of the processes that want to communicate. The processes need to know only each others identity to communicate. 2. A link is associated with exactly two processes. 3. Exactly one link exists between each pair of processes. • There are two ways of addressing namely • Symmetry in addressing- the sender and receive primitives are defined as Send(A, message)-send a message to process A Receive(B, message)-receive a message from B • Asymmetry in addressing- the sender and receive primitives are defined as Send(A, message)-send a message to process A Receive(id, message)-receive a message from any process with the corresponding id.
  • 38. In-direct Communication • With indirect communication, the messages are sent to and received from mailboxes, or ports. • The sender and receive primitives are defined as Send(M, message)-send a message to mailbox M Receive(M, message)-receive a message from mailbox M. • The communication link has the following properties 1. A link is established between a pair of processes only if both members of the pair have a shared mailbox. 2. A link is may be associated with more than two processes. 3. A number of different links may exists between each pair of communicating processes, with each link corresponding to one mailbox.
  • 39. Buffering: • A link has some capacity that determines the number of messages that can reside in it temporarily. • Zero capacity- queue length of maximum is 0. no messages is waiting in a queue. The sender must wait until the recipient receives the messages. • Bounded capacity- the queue has finite length n. thus at most n messages can reside in it. • Unbounded capacity- the queue has potentially infinite length. Thus any number of messages can wait in it.
  • 40. Synchronization: • Message passing may be either blocking or non blocking. • Blocking send- the sender blocks itself till the message sent by it is receive by the receiver. • Non- Blocking send- the sender does not block itself after sending the messages but continues with its normal operation. • Blocking receive- the receiver block itself until it receives the message. • Non- Blocking receive- the receiver does not block itself.
  • 42. Threads- Overview: • A thread is the basic unit of CPU utilization. A thread provides away to improve application performance through parallelism. • It is sometimes called as light weight process. • It is the flow of execution through the process code, thread ID, a program counter, a register set and a stack. • Each thread belongs to any of one process and no thread can exist outside a process.
  • 43. • It share with other threads belonging to the same process its code section, data section, and resources such as open files and signals. • A traditional or heavy weight process has a single thread of control. • If the process has multiple threads of control, it can do more than one task at a time.
  • 44. Process Threads Process is a heavy weight or resource intensive Thread is light weight taking lesser resources than a process. Process switching needs interaction with the OS Thread switching does not need interaction with the OS In multiprocessing environments each process executes the same code but has its own memory and file resources All threads can share same set of open files, child processes. If one process is blocked, then no other process can execute until the first process is unblocked When one thread is blocked and waiting, second thread in the same task can run. Multiple processes without using the thread use more resources Multiple threaded process uses fewer resources In multiple process, each process operates independently of the others. One thread can read, write or change another thread’s data.
  • 45. Benefits of Multithreads • Enhanced throughput of the system: When the process is split into many threads, and each thread is treated as a job, the number of jobs done in the unit time increases. That is why the throughput of the system also increases. • Effective Utilization of Multiprocessor system: When you have more than one thread in one process, you can schedule more than one thread in more than one processor. • Faster context switch: The context switching period between threads is less than the process context switching. The process context switch means more overhead for the CPU. • Responsiveness: When the process is split into several threads, and when a thread completes its execution, that process can be responded to as soon as possible. • Communication: Multiple-thread communication is simple because the threads share the same address space, while in process, we adopt just a few exclusive communication strategies for communication between two processes. • Resource sharing: Resources can be shared between all threads within a process, such as code, data, and files. Note: The stack and register cannot be shared between threads. There is a stack and register for each thread.
  • 46. Need of Thread: • It takes less time to create a new thread in an existing process than to create a new process. • Threads can share the common data, they do not need to use Inter- Process communication. • Context switching is faster when working with threads. • It takes less time to terminate a thread than a process. Types of Threads • In the Operating system, there are two types of threads. Kernel level thread User-level thread
  • 47. User-level thread • The OS does not recognize the user-level thread. • User threads can be easily implemented by the user. If a user performs a user-level thread blocking operation, the whole process is blocked. • The kernel level thread does not know nothing about the user level thread. The kernel-level thread manages user-level threads as if they are single-threaded processes. Advantages of User-level threads • The user threads can be easily implemented than the kernel thread. • User-level threads can be applied to such types of OS that do not support threads at the kernel-level. • It is faster and efficient. • Context switch time is shorter than the kernel-level threads. • It does not require modifications of the operating system. • User-level threads representation is very simple. The register, PC, stack, and mini thread control blocks are stored in the address space of the user-level process. • It is simple to create, switch, and synchronize threads without the intervention of the process. Disadvantages of User-level threads • User-level threads lack coordination between the thread and the kernel. • If a thread causes a page fault, the entire process is blocked.
  • 48. Kernel level thread • The kernel thread recognizes the operating system. • There is a thread control block and process control block in the system for each thread and process in the kernel-level thread. • The kernel-level thread is implemented by the operating system. The kernel knows about all the threads and manages them. • The kernel-level thread offers a system call to create and manage the threads from user- space. The implementation of kernel threads is more difficult than the user thread. • Context switch time is longer in the kernel thread.
  • 49. Advantages of Kernel-level threads • The kernel-level thread is fully aware of all threads. • The scheduler may decide to spend more CPU time in the process of threads being large numerical. • The kernel-level thread is good for those applications that block the frequency. Disadvantages of Kernel-level threads • The kernel thread manages and schedules all threads. • The implementation of kernel threads is difficult than the user thread. • The kernel-level thread is slower than user-level threads.
  • 51. • Multicore programming helps to create concurrent systems for deployment on multicore processor and multiprocessor systems. • A multicore processor system is basically a single processor with multiple execution cores in one chip. • A Field-Programmable Gate Array (FPGA) is might be included in a multiprocessor system. A FPGA is an integrated circuit containing an array of programmable logic blocks and a hierarchy of reconfigurable interconnects. • Input data is processed by to produce outputs. It can be a processor in a multicore or multiprocessor system, or a FPGA. Advantages: • Multicore and FPGA processing helps to increase the performance of an embedded system. • Also helps to achieve scalability, so the system can take advantage of increasing numbers of cores and FPGA processing power over time. • Concurrent systems that we create using multicore programming have multiple tasks executing in parallel. This is known as concurrent execution. When multiple parallel tasks are executed by a processor, it is known as multitasking. Disadvantages: • A CPU scheduler, handles the tasks that execute in parallel. The CPU implements tasks using OS threads. So that tasks can have some data transfer between them, such as data transfer between a data acquisition module and controller for the system. Data transfer occurs when there is a data dependency.
  • 54. Multithreading models: • Multithreading allows the application to divide its task into individual threads. • In multi-threads, the same process or task can be done by the number of threads. • With the use of multithreading, multitasking can be achieved. • The main drawback of single threading systems is that only one task can be performed at a time, so to overcome the drawback of this single threading, there is multithreading that allows multiple tasks to be performed.
  • 55. There exists three established multithreading models Many to one multithreading model One to one multithreading model Many to Many multithreading models
  • 56. Many to one multithreading model: • The many to one model maps many user levels threads to one kernel thread. • This type of relationship facilitates an effective context- switching environment, easily implemented even on the simple kernel with no thread support. Disadvantage • since there is only one kernel-level thread schedule at any given time, this model cannot take advantage of the hardware acceleration offered by multithreaded processes or multi-processor systems. • In this, all the thread management is done in the user space. If blocking comes, this model blocks the whole system.
  • 57. One to one multithreading model • The one-to-one model maps a single user-level thread to a single kernel-level thread. • This type of relationship facilitates the running of multiple threads in parallel. • The generation of every new user thread must include creating a corresponding kernel thread causing an overhead, which can hinder the performance of the parent process. • Windows series and Linux operating systems try to tackle this problem by limiting the growth of the thread count.
  • 58. Many to Many Model multithreading model • In this type of model, there are several user-level threads and several kernel-level threads. • The number of kernel threads created depends upon a particular application. • The developer can create as many threads at both levels but may not be the same. • The many to many model is a compromise between the other two models. • In this model, if any thread makes a blocking system call, the kernel can schedule another thread for execution. Also, with the introduction of multiple threads, complexity is not present as in the previous models. • Though this model allows the creation of multiple kernel threads, true concurrency cannot be achieved by this model. This is because the kernel can schedule only one process at a time.
  • 59. Threading issues: 1. Fork and exec system call: • Fork system call is used to create a separate duplicate process. • If one thread in a program calls fork system calls, then  Creating a new process that duplicates all threads.  Creating a new process that duplicates only one thread that invoked the fork. • If a thread invokes Exec system call, the program specified in the parameter to exec will replace the entire process including all threads.
  • 60. Factors for Differentiation fork() exec() Invoking fork() creates a new duplicate child process of the process that invoked fork() exec() replaces a process that invokes it with a new process provided in its parameter. Process id The child process and parent process have unique process id. The new process and the replaced process have the same process id. Execution The parent and child process start simultaneous execution from the instruction just after fork(). The currently running process is terminated and the exec() start execution of the new process from its entry point. Arguments No arguments are passed to fork() system call. Basically, three or more arguments are passed to the exec() system call. Format Pid=fork(); exec(cont char *filename, char* const argv[], char* const envp[])
  • 61. 2. Cancellation: • Thread cancellation means terminating a thread before it has completed. • A thread that is to be cancelled is referred to as target thread. • Asynchronous cancellation- one thread immediately terminates the target thread. • Deferred cancellation- the target thread can periodic check if it should terminate, allowing an opportunity to terminate itself in an orderly fashion. 3. Signal handling: • A signal is used to notify a process that a particular event has occurred. • A signal may be received either synchronous or asynchronous . • Every signal may be handled by one of the two handlers. • Default signal handler- run by the kernel. • User defined handler-run by the user defined functions. • Delivering the signal is more complicated in multithreading program.
  • 62. 4. Thread pools: • When creating a separate thread, multithread server has some potential problems. • Amount of time required to create the thread prior servicing the request. • Discarding the thread once it completes the task. • There is no bound on the number of threads concurrently active in the system. • Create number of threads at process startup and place them into a pool, where they sit and wait for work. • When a server receives a request, it awakens a thread from this pool, if one is available. • If thread completes its service, it returns to the pool.