0% found this document useful (0 votes)
35 views

Process

The document discusses processes and threads. It defines a process as a program in execution that consists of code, activity, stack, data, and heap. Processes exist in states like new, ready, running, waiting, and terminated. Each process has a process control block (PCB) that contains its state and resources. There are long term, short term, and medium term schedulers that manage processes. Interprocess communication allows processes to share data through methods like shared memory and message passing. Threads are lightweight processes that exist within a process and can improve performance through parallelism. Threads can be implemented at the user or kernel level. [/SUMMARY]

Uploaded by

Srijan singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Process

The document discusses processes and threads. It defines a process as a program in execution that consists of code, activity, stack, data, and heap. Processes exist in states like new, ready, running, waiting, and terminated. Each process has a process control block (PCB) that contains its state and resources. There are long term, short term, and medium term schedulers that manage processes. Interprocess communication allows processes to share data through methods like shared memory and message passing. Threads are lightweight processes that exist within a process and can improve performance through parallelism. Threads can be implemented at the user or kernel level. [/SUMMARY]

Uploaded by

Srijan singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Processes

Process Concept
• Process is a Program in execution.
• A process defines the fundamental unit of computation for the computer.
• A process can run to completion only when all requested resources have been
allocated to the process.
• Two or more processes could be executing the same program, each using their
own data and resources.
Process Concept
Multiple parts of a process
◦ The program code, also called text section
◦ Current activity including program counter
◦ Stack containing temporary data
◦ Function parameters, return addresses, local variables
◦ Data section containing global variables
◦ Heap containing memory dynamically allocated during run time
Process and Program
• Process is a dynamic entity that is a program in execution, while Program is a
static entity made up of program statement.
• A process is a sequence of information executions, while Program contains the
instructions.
• Process exists in a limited span of time, while a program exists at single place in
space and continues to exist.
• Two or more processes could be executing the same program, each using their
own data and resources.
Process States
• When process executes, it changes state. Process state is defined as the current
activity of the process.
• A process exists in one of the five states:
o New: A process that just been created.
o Ready: Ready processes are waiting to have the processor allocated to them by the
operating system so that they can run.
o Running: The process that is currently being executed. A running process possesses all the
resources needed for its execution, including the processor.
o Waiting: A process that can not execute until some event occurs such as the completion
of an I/O operation. The running process may become suspended by invoking an I/O
module.
o Terminated: A process that has been released from the pool of executable processes by
the operating system.
Process States
Process Control Block
Each process contains the process control block (PCB).
PCB is the data structure used by the operating
system.
Operating system groups all information that it needs
about particular process.
Scheduling Queues
Schedulers
Schedulers are of three types.
1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
Long term scheduler
• It is also called job scheduler.
• Long term scheduler determines which programs are admitted to the system
for processing.
• Job scheduler selects processes from the queue and loads them into memory
for execution.
• The primary objective of the job scheduler is to provide a balanced mix of jobs,
such as I/O bound and processor bound. It also controls the degree of
multiprogramming.
Short term scheduler
• It is also called CPU scheduler.
• It is the change of ready state to running state of the process.
• CPU scheduler selects from among the processes that are ready to execute and
allocates the CPU to one of them.
• Short term scheduler also known as dispatcher.
• Short term scheduler is faster than long tern scheduler.
Medium term Scheduler
• Medium term scheduling is part of the swapping function.
• It reduces the degree of multiprogramming.
• The medium term scheduler is in charge of handling the swapped out-
processes.
Context Switch
• 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
• Context-switch time is overhead; the system does no useful work while
switching
◦ The more complex the OS and the PCB  the longer the context switch
Operations on Processes
System must provide mechanisms for:
◦ process creation,
◦ process termination
Process Creation
Parent process create child 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
◦ Parent and children share all resources
◦ Children share subset of parent’s resources
◦ Parent and child share no resources

Execution options
◦ Parent and children execute concurrently
◦ Parent waits until children terminate
Process Termination
• Process executes last statement and then asks the operating system to delete
it using the exit() system call.
• Returns status data from child to parent (via wait())
• Process’ resources are deallocated by operating system

• Parent may terminate the execution of children processes using the


abort() system call. Some reasons for doing so:
• Child has exceeded allocated resources
• Task assigned to child is no longer required
• The parent is exiting and the operating systems does not allow a child to continue if its
parent terminates
Interprocess Communication
Processes within a system may be independent or cooperating
Cooperating process can affect or be affected by other processes, including sharing data
Reasons for cooperating processes:
◦ Information sharing
◦ Computation speedup
◦ Modularity
◦ Convenience

Cooperating processes need interprocess communication (IPC)


Two models of IPC
◦ Shared memory
◦ Message passing
Communications Models
(a) Message passing.
• Naming
• Synchronization
• Buffering
(b) Shared memory.
Message Passing Systems
• Naming
• Direct Communication
• Indirect Communication (using a mailbox)

•Synchronization
• Blocking send
• Nonblocking send
• Blocking receive
• Nonblocking receive

•Buffering
• Zero capacity
• Bounded capacity
• Unbounded capacity
Thread
A thread is called a light weight process.
A thread is a flow of execution through the process code, with its
own program counter, system registers and stack.
Threads are a popular way to improve application performance
through parallelism.
Each thread belongs to exactly one process and no thread can exist
outside a process.
Single-threaded and Multi-threaded processes
Benefits of Multithreaded Environment
Responsiveness
Resource Sharing
Economy
Scalability
Types of Thread
Thread is implemented in two ways :
1. User Level
2. Kernel Level
User Level Thread
All of the work of thread management is done by the application and the
kernel is not aware of the existence of threads.
The thread library contains code for creating and destroying threads.
The application begins with a single thread and begins running in that
thread.
Kernel Level Threads
Thread management is done by the Kernel.
No thread management code in the application area.
Kernel threads are supported directly by the operating system.
The Kernel performs thread creation, scheduling and management in
Kernel space.
Kernel threads are generally slower to create and manage than the
user threads.
User Level vs Kernel Level Threads
S.No. User Level Threads Kernel Level Thread

1 User level thread are faster to create and Kernel level thread are slower to create and
manage. manage.
2 Implemented by a thread library at the user Operating system support directly to Kernel
level. threads.
3 User level thread can run on any operating Kernel level threads are specific to the operating
system. system.
4 Multithread application cannot take Kernel routines themselves can be multithreaded.
advantage of multiprocessing.
Advantages of Thread
1. Thread minimize context switching time.
2. Use of threads provides concurrency within a process.
3. Efficient communication.
4. Economy- It is more economical to create and terminate threads than processes.
5. Utilization of multiprocessor architectures– The benefits of multithreading can be greatly
increased in a multiprocessor architecture.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread
facility.
Solaris is a good example of the combined approach.
In a combined system, multiple threads within the same application can run in parallel
on multiple processors.
Multithreading models are of three types:
1. Many to many relationship.
2. Many to one relationship.
3. One to one relationship.
Many to Many Model

• The many-to-many model multiplexes


many user-level threads to a smaller or
equal number of kernel threads.
• Developers can create as many user
threads as necessary, and the
corresponding kernel threads can run
in parallel on a multiprocessor.
Many to One Model

• The many-to-one model maps many


user-level threads to one kernel
thread.
• Since only one thread can access the
kernel at a time, multiple threads are
unable to run in parallel on
multiprocessors
One to One Model
• The one-to-one model maps each
user thread to a kernel thread.
• It provides more concurrency than
the many-to-one model by allowing
another thread to run when a thread
makes a blocking system call.
• Drawback:- creating a user thread
requires creating the corresponding
kernel thread.
Windows and Linux Threads
Windows thread implements the one-to-one mapping.
Each Window thread contains
◦ A thread id
◦ Register set representing state of processor
◦ Separate user and kernel stacks for when thread runs in user mode or kernel mode
◦ Private data storage area used by run-time libraries and dynamic link libraries (DLLs)

Linux refers to them as tasks rather than threads


Thread creation is done through clone() system call
clone()allows a child task to share the address space of the parent task (process)
End of Chapter

You might also like