Chapter - 3 Process
Chapter - 3 Process
12/11/2023 1
Chapter 3
Processes
12/11/2023 2
Content
Recall of Processes
Introduction of threads
Threads Implementation
Servers
Code migration
3
Recall of Processes
• Communication can be takes place between processes.
5
Processes…..
2N
▪ A process includes:
✓ code segment
✓ data segment
Address space
6
Costs of Processes
• Processes are costly b/c creating a process requires creation of an
entire
7
Process Creation
System initialization
8
Process Termination
▪ Conditions which terminate processes
9
Process States
• The following are possible process states;
10
Context Switch
• Inter-process communication is expensive: need context switching
• 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.
11
Cooperating processes
• Cooperating processes need to share information (data). Since each
process has its own address space, operating system mechanisms are
needed to let processes exchange information.
• Shared Memory
• Message-passing
12
Threads and their Implementation
13
1
4
Introduction
• How are processes and threads related?
• A thread of execution is
• Very little overheads (thread switching is easy (it use process memory)
16
Thread Structure….
• Process is unit of allocation
• Note
17
Thread Structure….
• What threads add to the process model?
18
Thread Structure….
• Each thread has its own program counter, registers, stack, and
state;
19
Difference between Process and Thread
Comparison Basis Process Thread
Definition A process is a program under execution A thread is a lightweight process that can
i.e. an active program. be managed independently by a scheduler
Context switching Processes require more time for context Threads require less time for context
time switching as they are heavier. switching as they are lighter than
processes.
Memory Sharing Processes are totally independent and A thread may share some memory with its
don’t share memory. peer threads.
Communication Communication between processes Communication between threads requires
requires more time than between threads. less time than between processes.
Blocked If a process gets blocked, remaining If a user level thread gets blocked, all of its
processes can continue execution. peer threads also get blocked.
Resource Processes require more resources than Threads generally need less resources than
Consumption threads. processes.
Dependency Individual processes are independent of Threads are parts of a process and so are
each other. dependent.
Data and Code Processes have independent data and code A thread shares the data segment, code
sharing segments. segment, files etc. with its peer threads.
Treatment by OS All the different processes are treated All user level peer threads are treated as a
separately by the operating system. single task by the operating system.
Time for creation Processes require more time for creation. Threads require less time for creation.
Time for termination Processes require more time for Threads require less time for termination.
termination. 20
Cont.…
• Similarities between Process and Thread
– Like processes threads share CPU and only one thread is running
at a time.
✓Exit voluntary when it’s finish its job or it can be killed from
outside.
22
Thread Usage in Non-distributed Systems
• Single threaded process
23
Thread Usage in Non-distributed Systems
Multithreads Process
24
Cont.….
• In non distributed systems,
26
2
7
Cont.…
• Thread Usage –Why do we need threads?
• e.g., a word processor has different parts for
✓ interacting with the user
✓ formatting the page as soon as changes are made
✓ timed savings (for auto recovery)
✓ spelling and grammar checking, etc.
• Easier to create and destroy than processes since they do not have any
resources attached to them
28
Thread Implementation….
▪ User-level threads (User Managed)
✓ Implemented by thread library & kernel knows nothing about them
29
Thread Implementation….
▪ Drawback is how blocking system calls are implemented.
30
Difference b/n User level threads and Kernel level threads
User Level Thread Kernel Level Thread
User thread are implemented by users. Kernel threads are implemented by OS.
OS doesn’t recognized user level
Kernel threads are recognized by OS.
threads.
Implementation of Kernel thread is
Implementation of User threads is easy.
complex.
Context switch time is less. Context switch time is more.
Context switch requires no hardware Context switch requires hardware
support. support.
If one kernel thread performs blocking
If one user level thread performs
operation, then another thread within
blocking operation, then entire process
the same process can continue
will be blocked.
execution.
31
Combining kernel-level and user-level threads
32
Lightweight Process (LWP)
• A hybrid approach
• Reside in kernel
33
Light-Weight Process
• Several advantages
•Cheap, will not block entire process, extends to multiprocessing
environment
34
Threads in Distributed Systems
▪ Multithreaded Clients
✓ each can display the results as it gets its part of the page
35
Cont.…
❖ Multithreaded Servers: Servers can be constructed in three ways
▪ Finite-state machine
Model Characteristics
37
3
Cont.….
8
Anatomy of Clients
• User Interfaces
✓ it has the X kernel: the part of the OS that controls the terminal
(monitor, keyboard, pointing device like a mouse) and is hardware
dependent.
3
9
Cont.….
• Client-Side Software for Distribution Transparency
✓ Ensure the request is served and wait for the next incoming request
✓ Iterative server
✓ Concurrent server
• Stateful server
– So, Ship(move) part of the client application to the server and send
only the result across the network
44
Cont.…
Reasons for Migrating Code
45
Models for Code Migration
• Code migration doesn’t only mean moving code;