You are on page 1of 27

CHAPTER TWO

PROCESS MANAGEMENT
2.1 The Process Concept
2.2 Process Life Cycles
2.3 Process Control
2.4 Threads

1 / 15
CH-02: Process Management ...

In Old-days, Computer system allowed only one program to be executed at


a time

♣ Control of the system and had access to all the system’s resources.
In Modern-days, Computer systems allow Multiple programs to be loaded
into memory and executed concurrently.

2 / 15
CH-02: Process Management ...

In Old-days, Computer system allowed only one program to be executed at


a time

♣ Control of the system and had access to all the system’s resources.
In Modern-days, Computer systems allow Multiple programs to be loaded
into memory and executed concurrently.

♣ Required firmer(strong) control and more compartmentalization of the
various programs ⇒ PROCESS
⇒ What is PROCESS ?

2 / 15
CH-02: Process Management ...

In Old-days, Computer system allowed only one program to be executed at


a time

♣ Control of the system and had access to all the system’s resources.
In Modern-days, Computer systems allow Multiple programs to be loaded
into memory and executed concurrently.

♣ Required firmer(strong) control and more compartmentalization of the
various programs ⇒ PROCESS
⇒ What is PROCESS ?
Process is
is an instance of executing program.
is an entity which represent the basic unit of work to be implemented by
system.
Is Program code = Process ?

2 / 15
CH-02: Process Management ...

In Old-days, Computer system allowed only one program to be executed at


a time

♣ Control of the system and had access to all the system’s resources.
In Modern-days, Computer systems allow Multiple programs to be loaded
into memory and executed concurrently.

♣ Required firmer(strong) control and more compartmentalization of the
various programs ⇒ PROCESS
⇒ What is PROCESS ?
Process is
is an instance of executing program.
is an entity which represent the basic unit of work to be implemented by
system.
Is Program code = Process ? NOP
Process is represented by:
Program Counter: is special-purpose register that is used by the processor
to hold the address of the next instruction to be executed.
Stack : Which contains temporary data;

2 / 15
CH-02: Process Management ...

Process....
Process is represented by...
Data section: Which contains global variables.
Heap: Which is memory that is dynamically allocated during process run
time
A program by itself is not a process;
its just Passive entity; whereas a process is an active entity
When does program become process?

♣ When an executable file is loaded into memory
Two common techniques for loading
Double-clicking an icon representing the executable file.
Entering the name of the executable file on the command line

3 / 15
CH-02: Process Management ...
When A program executes it passes via different states.
Process states:
1 New- The process is being created.
2 Running- Instructions are being executed.
3 Waiting - The process is waiting for some event to occur (such as an I/O
completion or reception of a signal).
4 Ready- The process is waiting to be assigned to a processor.
5 Terminated- The process has finished execution

4 / 15
CH-02: Process Management ...
When A program executes it passes via different states.
Process states:
1 New- The process is being created.
2 Running- Instructions are being executed.
3 Waiting - The process is waiting for some event to occur (such as an I/O
completion or reception of a signal).
4 Ready- The process is waiting to be assigned to a processor.
5 Terminated- The process has finished execution

Figure: Process States or Process Lifecycle

4 / 15
CH-02: Process Management ...

⇒ How Process is represented in OPerating system.



♣ Process Control Block(PCB)

PCB
is a data structure maintained by the operating system for every processes.
identified by PID.
It contains Multitude information associated with a specific process. What
informations?

5 / 15
CH-02: Process Management ...

⇒ How Process is represented in OPerating system.



♣ Process Control Block(PCB)

PCB
is a data structure maintained by the operating system for every processes.
identified by PID.
It contains Multitude information associated with a specific process. What
informations?
Process State: current state of processes→ ready, running, waiting or Other.
Program counter: Address of the next instruction to be executed for this
process.
Process ID: an Identifier for each processes.
Pointer : which points to the parent process.
CPU registers: kind of memory where processes need to be stored for
execution for running process.
CPU-scheduling information: includes process priority and other scheduling
info. required to schedule the process.
Accounting information: This includes the amount of CPU used for process
execution, time limit, execution ID etc.
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.

5 / 15
CH-02: Process Management ...
A process is a program that performs a single thread of execution.
This single thread of control allows the process to perform only one task
at a time.

6 / 15
CH-02: Process Management ...
A process is a program that performs a single thread of execution.
This single thread of control allows the process to perform only one task
at a time.
MULTIPROGRAMMING - a process to have multiple threads of execution
⇒ to perform more than one task at a time
• What is Thread then ?
Thread is ..
A basic unit for CPU Utilization. OR
are lightweight processes.
also a software approach to improve performance of operating system by
reducing the Overhead of classical Process.
Each threads belongs to one process and represent a separate flow of
execution.
It comprises a thread ID, a program counter, a register set, and a stack.
BUT, Shares the code section, data section, and other operating-system
resources.
A process with Single threads of control ⇒ Single-threaded process.
A process with multiple threads of control ⇒ Multi-threaded process.
6 / 15
CH-02: Process Management ...

Figure: Single-threaded process Figure: Multi-threaded process

7 / 15
CH-02: Process Management ...
Benefits Of Multi-threaded process!
Responsiveness
Resource sharing
Economy
Scalability
I How many processor your Machine has?

♣ Is it core i3, core i5, core i7! W@ is that?

8 / 15
CH-02: Process Management ...
Benefits Of Multi-threaded process!
Responsiveness
Resource sharing
Economy
Scalability
I How many processor your Machine has?

♣ Is it core i3, core i5, core i7! W@ is that? ⇒ Multicore Programming

8 / 15
CH-02: Process Management ...
Benefits Of Multi-threaded process!
Responsiveness
Resource sharing
Economy
Scalability
I How many processor your Machine has?

♣ Is it core i3, core i5, core i7! W@ is that? ⇒ Multicore Programming

Multicore Programming
A programming in system design to place multiple computing cores on a
single chip, where each core appears as a separate processor to the
operating system.
Utilized for deployment on Multicore processor and Multiprocessor systems
Multicore processor system is a single processor with multiple execution cores in
one chip.
Multiprocessor system has multiple processors on the motherboard or chip
Multithreaded programming provides a mechanism for more efficient use of
multiple cores and improved concurrency.
CONCURRENCY and PARALLALISM ⇒ way of executing process in Multi-core
systems

8 / 15
CH-02: Process Management ...

⇒ Is any challange in programming multicore system ?

9 / 15
CH-02: Process Management ...

⇒ Is any challange in programming multicore system ? Definately?



Check it out in detail
A Thread library: provides the programmer with an API for creating and
managing threads.
There are two primary ways of implementing a thread library.
1 To provide a library entirely in user space with NO kernel support

USER-LEVEL THREADS! : Everything is in User-mode / space.
2 To implement at the kernel-space, library supported directly by the
operating system.

KERNEL-LEVEL THREADS!
Three main thread libraries:
1 POSIX Pthreads
2 Win32,
3 Java

9 / 15
CH-02: Process Management ...

Thread libraries...
1 POSIX Pthreads:
Stands for Portable Operating System Interface

is a set of standard operating system interfaces based on the Unix
operating system
Pthreads refers to the POSIX standard defining an API for thread creation
and synchronization.
It is not Implementation rather its defines thread behavior.
2 Win32 Threads
The technique for creating threads using the Win32 thread library.
Header file must be included in case of using the Win32 API such thread
libraries, such as windows.h
3 Java Threads
The Java thread API allows thread creation and management directly in
Java programs.
Two techniques for creating threads:
Create a new class that is derived from the Thread class
To override its run() method.

10 / 15
CH-02: Process Management ...

⇒ The fork() and exec() System Calls.


Fork system call creates a new process by duplicating the calling process.
The new process is referred to as the child process
Thread cancellation is the task of terminating a thread before it has
completed
A thread that is to be canceled is often referred to as the target thread
Cancelled in two ways:
Asynchronous cancellation: One thread immediately terminates the target
thread.
Deferred cancellation. The target thread periodically checks whether it
should terminate, allowing it an opportunity to terminate itself in an orderly
fashion.

11 / 15
CH-02: Process Management ...

InterProcess Communication (IPC)


A mechanism which allows cooperating process to exchange data and
information is IPC
2 types of process on the basis of Synchronization.
Independent Process: Execution of one process does not affects the
execution of other process
Cooperative Process: Execution of one process does not affects the
execution of other process
Why Process communication is relevent as such?
1 Infromation Sharing
2 Computational Speed
3 Modularity
4 Convenience
Two fundamental models of interprocess communication
1 Shared memory
2 Message passing

12 / 15
CH-02: Process Management ...

Shared memory
A Region of memory that is shared by cooperating processes is established.
Processes can then exchange information by reading and writing data to the
shared region.
A Shared-memory region resides in the address space of the process creating
the shared-memory segment.
A Processes that wish to communicate using this shared-memory segment
must attach it to their address space
Is a solution for Producer-Consumer Problem.

13 / 15
CH-02: Process Management ...

Shared memory
A Region of memory that is shared by cooperating processes is established.
Processes can then exchange information by reading and writing data to the
shared region.
A Shared-memory region resides in the address space of the process creating
the shared-memory segment.
A Processes that wish to communicate using this shared-memory segment
must attach it to their address space
Is a solution for Producer-Consumer Problem.What is it?
Collection Of cooperating processes.

Producer process produces information that is consumed by a consumer process.
Message-Passing

13 / 15
CH-02: Process Management ...

Shared memory
A Region of memory that is shared by cooperating processes is established.
Processes can then exchange information by reading and writing data to the
shared region.
A Shared-memory region resides in the address space of the process creating
the shared-memory segment.
A Processes that wish to communicate using this shared-memory segment
must attach it to their address space
Is a solution for Producer-Consumer Problem.What is it?
Collection Of cooperating processes.

Producer process produces information that is consumed by a consumer process.
Message-Passing
Is a mechanism to allow processes to communicate and to synchronize their
actions without sharing the same address space
Relevant in distributed environment

The communicating processes may reside on different computers connected
by a network
Employe two operations

13 / 15
CH-02: Process Management ...

Shared memory
A Region of memory that is shared by cooperating processes is established.
Processes can then exchange information by reading and writing data to the
shared region.
A Shared-memory region resides in the address space of the process creating
the shared-memory segment.
A Processes that wish to communicate using this shared-memory segment
must attach it to their address space
Is a solution for Producer-Consumer Problem.What is it?
Collection Of cooperating processes.

Producer process produces information that is consumed by a consumer process.
Message-Passing
Is a mechanism to allow processes to communicate and to synchronize their
actions without sharing the same address space
Relevant in distributed environment

The communicating processes may reside on different computers connected
by a network
Employe two operations ⇒ send(message) and receive(message)

13 / 15
CH-02: Process Management ...

Figure: Process Communication Model by message Passing and shared memory


respectively

14 / 15
Thank you!
Questions + Suggestion ?!

15 / 15

You might also like