0% found this document useful (0 votes)
69 views17 pages

Os 3

The document discusses processes and threads in an operating system. A process is a program in execution that consists of code, data, and stack sections. It is represented in memory by a process control block (PCB) that stores process state and scheduling information. A process can create multiple threads to achieve parallelism within a single program. Threads share common code and data but have their own program counters and stacks. Using threads provides benefits like faster context switching and better utilization of multiprocessor systems compared to processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views17 pages

Os 3

The document discusses processes and threads in an operating system. A process is a program in execution that consists of code, data, and stack sections. It is represented in memory by a process control block (PCB) that stores process state and scheduling information. A process can create multiple threads to achieve parallelism within a single program. Threads share common code and data but have their own program counters and stacks. Using threads provides benefits like faster context switching and better utilization of multiprocessor systems compared to processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Operating system

Vikram Verma
AP
PIET , Samalkha
Syllabus

11/20/2022 Vikram Verma 2


Books
Text Books:

1.Operating Systems , PP Choudhary by PHI Learning Pvt Ltd.

Reference Books:

1.Operating Systems : Internals and Design Principles, William


Stallings, Pearson

2.Operating System Concepts”, Abraham Silberschatz, Peter


Baer Galvin, and Greg Gagne, Wiley

11/20/2022 Vikram Verma 3


Process Concept
• An OS executes a variety of programs that run as a process.

• Process – a program in execution; process execution must progress


in sequential fashion. No parallel execution of instructions of a
single process

• Multiple parts
– The program code, also called text section
– Current activity including program counter, processor registers
– Stack containing temporary data
• Function parameters, return addresses, local variables
– Data section containing global variables
– Heap containing memory dynamically allocated during run time
Process Concept (Cont.)

• Program is passive entity stored on disk (executable file);

• Process is active
– Program becomes process when an executable file is loaded into
memory

• Execution of program is started via GUI mouse clicks, command line


entry of its name, etc.

• One program can be several processes


– Consider multiple users executing the same program
Process in Memory
Process State
As a process executes, it changes state

• New: The process is being created

• Running: Instructions are being 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


Diagram of Process State
Process Control Block (PCB)
In an OS each process is represented by a Process Control box
(PCB) also called task control block. . Info associated with process

• Process state – running, waiting, etc.

• Program counter – address of next instruction

• CPU registers – contents of all process-centric registers

• CPU scheduling information- priorities, scheduling queue


pointers

• Memory-management information – memory allocated to the


process

• Accounting information – CPU used, clock time elapsed since


start, time limits

• I/O status information – I/O devices allocated to process, list


of open files
Example : Memory lay out of 03 Processes

• Let process A and B have 12


instructions each

• B has 04 instructions and 4th


instruction invokes I/O operation for
which process must wait

• Dispatcher program that switches


processor from one process to another.
It has 06 instructions

11/20/2022 Vikram Verma 10


Example : Traces of 03 process in memory

11/20/2022 Vikram Verma 11


Traces from processor’s point of view

• Assume : OS only allows a process to continue execution for a


maximum of 06 instruction cycles after which it is interrupted,
– This prevents any single process from monopolizing the
processor time

• Dispatcher executes same sequence of instructions because the


same functionality of the dispatcher is being executed

• 1st 06 instructions of A executed , then dispatcher program is


executed , 04 instructions of B , dispatcher program , 06
instructions of C and so on

11/20/2022 Vikram Verma 12


Hierarchy of processes - Thread
• A thread is a path of execution within a process.

• A process can contain multiple threads.

• A thread is also known as lightweight process.

• The idea is to achieve parallelism by dividing a process into multiple


threads.

• Example,
– In a browser, multiple tabs can be different threads.
– MS Word uses multiple threads: one thread to format the text,
another thread to process inputs, etc.

11/20/2022 Vikram Verma 13


Thread

Each thread has its own PC , stack and registers , but sharing common
code, data, and certain structures such as open files.

11/20/2022 Vikram Verma 14


Process vs Thread

11/20/2022 Vikram Verma 15


Advantages of Thread over Process
Responsiveness: If the process is divided into multiple threads,
if one thread completes its execution, then its output can be
immediately returned.

Faster context switch: Context switch time between threads is


lower compared to process context switch. Process context
switching requires more overhead from the CPU.

Effective utilization of multiprocessor system: If we have


multiple threads in a single process, then we can schedule
multiple threads on multiple processor. This will make process
execution faster.

11/20/2022 Vikram Verma 16


Advantages of Thread over Process
Resource sharing: Resources like code, data, and files can be
shared among all threads within a process. Stack and registers
can’t be shared among the threads.

Communication: Communication between multiple threads is


easier, as the threads shares common address space, while in
process we have to follow some specific communication
technique for communication between two process.

Enhanced throughput of the system: If a process is divided


into multiple threads, and each thread function is considered as
one job, then the number of jobs completed per unit of time is
increased, thus increasing the throughput of the system.

11/20/2022 Vikram Verma 17

You might also like