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

Operating System

This document discusses processes and threads from an operating system perspective. It defines processes as programs that are executing, with each process having its own address space, program counter, and CPU registers. A process control block (PCB) stores process information and control information. Threads are defined as paths of execution within a process that share the same memory space and other resources. The key differences between processes and threads are that threads share resources while processes have separate address spaces. User-level threads are managed by user applications while kernel-level threads are managed by the operating system kernel.

Uploaded by

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

Operating System

This document discusses processes and threads from an operating system perspective. It defines processes as programs that are executing, with each process having its own address space, program counter, and CPU registers. A process control block (PCB) stores process information and control information. Threads are defined as paths of execution within a process that share the same memory space and other resources. The key differences between processes and threads are that threads share resources while processes have separate address spaces. User-level threads are managed by user applications while kernel-level threads are managed by the operating system kernel.

Uploaded by

Selin Dandpat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Operating System

MC4109 (Unit1: Introduction)


Dr. Sumit Kumar Tetarave
Lecture-03
Course Content
• Unit-1
• Introduction
• Processes
• The process concept,
• System programmer's view of processes.
• The operating system's view of processes.
• Operating system services for process management.
• Scheduling algorithms, Performance evaluation.
• Unit-II
• Inter-process Communication and Synchronization
• Deadlock
• Unit-III
• Unit-IV
The process concept

OS
Program (Idle)

Set of
Instruction
Process
(executing)

Control
Information
+

Program

* Create DS to manage a process


The process concept (cont…)
1000 Address that can be accessible by this process
Process PCB during the execution
Identification info Process Control
Process Status info Block (Control Info) 0 – 100
200 – 300 Address space
2000 Process Control info 350 – 700 of process
0 execute in CPU 800 - 900
Program or Code
Stores the code that the processor 1000 – 2000
100 (Text Segment)
executes
200 Data If outside generated address then
Global and Static variables
Segment process will trap and abort
300
350
Stack Stores local variables for active procedure
700 calls, function parameters, return addresses
Shared *** O/S is responsible to
Optional Data Point top of stack add
part 800 Heap memory dynamically allocated
900 during run time
Process in memory
The process concept (cont…)
• Process Identification Info-
• This block contains process identifier, which is assigned by O/S
• In every o/s, it is pid -> non –ve integer value
• Process Status Info-
• Program counter: stores the counter which contains the address of the next instruction that
is to be executed for the process
• CPU registers: CPU registers which includes: accumulator, base, registers and general purpose
registers
• Process Control Info-
1. Process State
2. Process priority
3. Memory related info
4. I/O related info
5. Alarm (signals)
The process concept (cont…)
Process Control Block (PCB): Information associated with each process
• Pointer: a stack pointer which is required to be saved when the
process is switched from one state to another to retain the
current position of the process
• Memory limits: contains the information about memory management
system used by operating system. This may include the page
tables, segment tables etc.
• Open files list : includes the list of files opened for a process.
System programmer's view of processes
• Creating child processes and assigning priorities
• Terminating child processes
• Determining the status of child processes
System programmer's view of processes
(Cont…) fork() This is a system call that creates process
killed P P P prints
- Parent process 5
During execution P 5
main() 7
create Single processor then { i= 100
C1 C2 One of them start. int i;
Child process Let c start print( “5”);
C i= fork() Creates a child process
C11 Child process if(i==0) Let process ‘C’
6 print(“6”) identical in terms
May or may not killed
O/S strategy i= 0 else of code but
print(“7”) Different - address space,
UNIX } - data, etc.
Init

C1 C2 C3 System call returns ->


1. Child process Pid to the parent process
C4 2. Zero to the child process
C5
System programmer's view of processes (Cont…)
* Zombie State – After complete * System calls –
Keep data in MM User Mode
P Zombie 1 -> Kernel Mode Can’t use privilege inst.
O-> User Mode Reject it
After completion of CPU
All Childs then Program
C1 C2 C3
Remove all data
Simple
Kernel Instructions
* User mode – Application or user program Mode Privilege Inst
Instruction set
are execute.
Call fork() O/S
* Supervisor/Kernel mode – System program or
Simple Inst. Privilege Inst. routine
privilege instructions execute
are critical instructions
like I/O, memory related, etc.
System programmer's view of processes (Cont…)
Thread:
• A thread is a path/flow of execution within a process, with its own
– program counter,
– system registers and
– stack.
• Threads have same properties as of the process so they are called as light weight processes.
• Threads provide a way to improve application performance through parallelism
• Threads represent a software approach to improve performance of operating system by reducing the overhead
• For 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.
System programmer's view of processes (Cont…)
Thread: (Cont…)
• Each thread belongs to exactly one process
• No thread can exist outside a process
• Each thread represents a separate flow of control
• Threads have been successfully used in implementing network
servers and web server
• Provide a suitable foundation for parallel execution of applications on
shared memory multiprocessors.
System programmer's view of processes (Cont…)
System programmer's view of processes (Cont…)
• Difference between Process and Thread:
System programmer's view of processes (Cont…)
• Difference between Process and Thread: (cont…)
System programmer's view of processes (Cont…)
Advantage of Threads:
• Thread minimize context switching time
• Use of threads provides concurrency within a process
• Efficient communication
• Economy- It is more economical to create and context switch threads
• Utilization of multiprocessor architectures to a greater scale and efficiency

Types of Threads:
• Threads are implemented in following two ways
• User Level Threads -- User managed threads
• Kernel Level Threads -- Operating System managed threads acting on kernel, an operating
system core.
System programmer's view of processes (Cont…)
User Level Threads:

• In this case,
• application manages thread management
• kernel is not aware of the existence of threads.
• The thread library contains code
• for creating and destroying threads,
• for passing message and data between threads,
• for scheduling thread execution and
• for saving and restoring thread contexts.
• The application begins with a single thread and begins running in that
thread.
System programmer's view of processes (Cont…)
User Level Threads:
• Advantages
– Thread switching does not require Kernel mode privileges.
– User level thread can run on any operating system.
– Scheduling can be application specific in the user level thread.
– User level threads are fast to create and manage.
• Disadvantages
– In a typical operating system, most system calls are blocking.
– Multithreaded application cannot take advantage of multiprocessing.
System programmer's view of processes (Cont…)
Kernel Level Threads:

• In this case, thread management done by the Kernel.


• There is no thread management code in the application area.
• Kernel threads are supported directly by the operating system.
• Any application can be programmed to be multithreaded.
• All of the threads within an application are supported within a single process.
• The Kernel maintains context information for the process as a whole and for
individuals threads within the process.
• Scheduling by the Kernel is done on a thread basis.
• The Kernel performs thread creation, scheduling and management in Kernel
space.
• Kernel threads are generally slower to create and manage than the user threads.
System programmer's view of processes (Cont…)
Kernel Level Threads:
• Advantages
– Kernel can simultaneously schedule multiple threads from the same process on multiple processes.
– If one thread in a process is blocked, the Kernel can schedule another thread of the same process.
– Kernel routines themselves can multithreaded.
• Disadvantages
– Kernel threads are generally slower to create and manage than the user threads.
– Transfer of control from one thread to another within same process requires a mode switch to the
Kernel.
System programmer's view of processes (Cont…)
Multithreading Models:
• Some operating system provide a combined user level thread and Kernel
level thread facility.
• Solaris is a good example of this combined approach.
• In a combined system,
• multiple threads within the same application can run in parallel on multiple
processors and
• a blocking system call need not block the entire process.
• Multithreading models are three types
• One to one relationship: map each user-level thread to a kernel thread
• Many to one relationship: map many user-level threads to one kernel thread
• Many to many relationship: multiplexes many user-level threads to a smaller or
equal number of kernel threads
System programmer's view of processes (Cont…)
One to One Model:
• Each user-level thread maps to kernel thread
• Examples
– Windows NT/XP/2000
– Linux
– Solaris 9 and later
• This model provides more concurrency than the many to one model
• It also another thread to run when a thread makes a blocking system call
• It support multiple thread to execute in parallel on microprocessors
• Disadvantage of this model is that creating user thread requires the
corresponding Kernel thread
System programmer's view of processes (Cont…)
Many to One model:
• Many user-level threads mapped to single kernel thread
• Examples:
• Solaris Green Threads
• GNU Portable Threads
System programmer's view of processes (Cont…)
• Many to one model maps many user level threads to one Kernel level
thread
• Thread management is done in user space
• When thread makes a blocking system call, the entire process will be
blocked
• Only one thread can access the Kernel at a time, so multiple threads
are unable to run in parallel on multiprocessors.
• If the user level thread libraries are implemented in the operating
system in such a way that system does not support them then
• Kernel threads use the many to one relationship modes.
System programmer's view of processes (Cont…)
Many to Many model:
• Allows many user level threads to be mapped to many kernel threads
• Allows the operating system to create a sufficient number of kernel
threads
• E.g.,
• Solaris prior to version 9
• Windows NT/2000 with the
• ThreadFiber package
System programmer's view of processes (Cont…)
Two-level Thread model:
• Similar to M:M, except that it allows a user thread to be bound to
kernel thread
• Examples
– IRIX
– HP-UX
– Tru64 UNIX
– Solaris 8 and earlier
System programmer's view of processes (Cont…)
• Difference between User Level and Kernel Level Thread
System programmer's view of processes (Cont…)
User-Level Threads:
• Thread management done by user-level threads library
• Thread library entirely executed in user mode
• Cheap to manage threads
– Create: setup a stack • Examples
– POSIX Pthreads
– Destroy: free up memory – Mach C-threads
• Context switch requires few instructions – Solaris threads
– Java threads
– Just save CPU registers
– Done based on program logic
• A blocking system call blocks all peer threads
System programmer's view of processes (Cont…)
Kernel-level Threads:

• Supported by the Kernel


• Kernel is aware of and schedules threads
• A blocking system call, will not block all peer threads
• Expensive to manage threads
• Expensive context switch Examples:
• Kernel Intervention Newer versions of
– Windows
– UNIX
– Linux
Top Interview Questions:
1) What is the difference between process and program?
• A program while running or executing is known as a process.

2) What do you mean by a process?


• An executing program is known as process. There are two types of
processes:
• Operating System Processes
• User Processes
Top Interview Questions:
3) What is a thread?
• A thread is a basic unit of CPU utilization. In general, a thread is
composed of a thread ID, program counter, register set, and the stack.

4) Give some benefits of multithreaded programming.


• there is increased responsiveness to the user
• resource sharing within the process
• economy
• utilization of multiprocessing architecture
Course Content: Lecture 04
• Unit-1
• Introduction
• Processes
• The process concept,
• System programmer's view of processes.
• The operating system's view of processes.
• Operating system services for process management.
• Scheduling algorithms, Performance evaluation.
• Unit-II
• Inter-process Communication and Synchronization
• Deadlock
• Unit-III
• Unit-IV

You might also like