0% found this document useful (0 votes)
21 views30 pages

FHSS PT 02 Processes

1) A process is an abstraction of a running program. It enables doing multiple tasks simultaneously through rapid switching between processes. 2) Processes are created through system calls from existing processes or user requests. Processes terminate normally, through errors, or involuntarily by being killed. 3) Processes can be in running, ready, or blocked states. The lowest level of the OS handles interrupts and scheduling between processes.

Uploaded by

darius galeon
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)
21 views30 pages

FHSS PT 02 Processes

1) A process is an abstraction of a running program. It enables doing multiple tasks simultaneously through rapid switching between processes. 2) Processes are created through system calls from existing processes or user requests. Processes terminate normally, through errors, or involuntarily by being killed. 3) Processes can be in running, ready, or blocked states. The lowest level of the OS handles interrupts and scheduling between processes.

Uploaded by

darius galeon
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/ 30

Processes

Platform Technologies

Based on Based on Tanenbaum, Modern Operating Systems

1
Processes
• A process is an abstraction of a running program
• It enables doing several things at the same time
• support the ability to have (pseudo) concurrent operation
• Ex. consider a user PC ??
• In a multiprogramming system, the CPU switches from process to
process quickly, running each for tens or hundreds of milliseconds

Based on Tanenbaum, Modern Operating Systems 3 e 2


Process and Program
• A process is an activity of some
kind
• A program is something that
may be stored on disk, not doing
anything
• Ex: baking vs. recipe

Based on Tanenbaum, Modern Operating Systems 3 e 3


The Process Model
• All the runnable software on the computer, sometimes including the
operating system, is organized into a number of sequential processes
• To understand the system, it is much easier to think about a collection
of processes running in (pseudo) parallel
• This rapid switching back and forth is called multiprogramming

Based on Tanenbaum, Modern Operating Systems 3 e 4


The Process Model
a) Multiprogramming four programs.
b) Conceptual model of four independent, sequential processes.
c) Only one program is active at once.

(we assume there is only one CPU, simpler to understand)


Based on Tanenbaum, Modern Operating Systems 3 e 5
Process Creation
• Events which cause processes creation:
1. System initialization.
2. Execution of a process creation system call by a running process.
3. A user request to create a new process.
4. Initiation of a batch job.
• In all these cases, a new process is created by having an existing
process execute a process creation system call.

Based on Tanenbaum, Modern Operating Systems 3 e 6


Process Termination
• Events which cause process termination:
1. Normal exit (voluntary).
2. Error exit (voluntary).
3. Fatal error (involuntary).
4. Killed by another process (involuntary).

Based on Tanenbaum, Modern Operating Systems 3 e 7


Process States
• Three states a process may be in:
1. Running (actually using the CPU at that instant).
2. Ready (runnable; temporarily stopped to let another process run).
3. Blocked (unable to run until some external event happens).

Based on Tanenbaum, Modern Operating Systems 3 e 8


Implementation of Processes
• The lowest layer of a process-structured operating system handles
interrupts and scheduling.
• Above that layer are sequential processes.

Based on Tanenbaum, Modern Operating Systems 3 e 9


Process Table
• One entry per process
• Contains important information
about the process’ state
• Information that must be saved
when the process is switched
from running to ready or blocked
state so that it can be restarted
later

Based on Tanenbaum, Modern Operating Systems 3 e 10


Interrupt Handling and Scheduling
• Skeleton of what the lowest level of the operating system does when
an interrupt occurs.

Based on Tanenbaum, Modern Operating Systems 3 e 11


Modelling Multiprogramming
• CPU utilization as a function of the number of processes in memory.

Based on Tanenbaum, Modern Operating Systems 3 e 12


Threads
• In many applications, multiple activities are going on at once
• Threads give the ability for the parallel entities to share an address
space and all of its data
• not possible with multiple processes (with their separate address spaces)
• Threads are lighter weight than processes, so they are easier (i.e.,
faster) to create and destroy
• Threads allow computing and IO activities to overlap

Based on Tanenbaum, Modern Operating Systems 3 e 13


Thread Usage - A Word Processor

• First thread interacts with the user.


• Second thread handles reformatting in the background.
• Third thread handles the disk backups.
Based on Tanenbaum, Modern Operating Systems 3 e 14
Thread Usage - A Multithreaded Web Server

• The dispatcher reads incoming requests for work from the


network and chooses an idle (i.e., blocked) worker thread to
hand the request
Based on Tanenbaum, Modern Operating Systems 3 e 15
The Classical Thread Model
• Multithreading is the situation of allowing multiple threads in the
same process
(a) Three processes each with one thread. (b) One process with three threads.

Based on Tanenbaum, Modern Operating Systems 3 e 16


The Classical Thread Model
• The first column lists some items shared by all threads in a process.
• The second one lists some items private to each thread.

Based on Tanenbaum, Modern Operating Systems 3 e 17


Advantages of Thread over Process
• Responsiveness:
• If the process is divided into multiple threads, one thread can complete its
execution and its output can be immediately returned.
• Faster context switch:
• Context switch time between threads is lower compared to process context
switch. Process context switching needs more CPU overhead.
• Effective utilization of multiprocessor system:
• If we have multiple threads in a single process, then we can schedule multiple
threads on multiple processor.

Based on Tanenbaum, Modern Operating Systems 3 e 18


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)
• 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.
Based on Tanenbaum, Modern Operating Systems 3 e 19
Inter-process Communication (IPC)
• Processes frequently need to • Mechanisms for IPC:
communicate with other • Atomic read/write
processes: • Locks
• To pass information from process • Semaphores
to another • Monitors
• To enable proper sequencing • Message Passing
when dependencies are present
• To ensure that no two processes
are ever in their critical regions at
the same time.

Based on Tanenbaum, Modern Operating Systems 3 e 20


Race Conditions
• Two or more processes are
reading or writing some shared
data and the final result depends
on who runs precisely when
• Ex. two processes want to access
the printer spooler directory at
the same time

Based on Tanenbaum, Modern Operating Systems 3 e 21


Conditions Required to Avoid Race Condition
1. No two processes may be simultaneously inside their critical regions.
– Mutual Exclusion (mutex)
2. No assumptions may be made about speeds or the number of CPUs.
– No Assumption
3. No process running outside its critical region may block other processes.
– Progress
4. No process should have to wait forever to enter its critical region.
– No Starvation

Based on Tanenbaum, Modern Operating Systems 3 e 22


Mutual Exclusion using Critical Regions
• Critical region – the part of the program where shared variables are
accessed

Based on Tanenbaum, Modern Operating Systems 3 e 23


Mutual Exclusion with Busy Waiting
• Disabling interrupts
• Each process disables all interrupts just after entering its critical region and
re-enable them just before leaving it
• In a multicore (i.e., multiprocessor system) disabling the interrupts of one
CPU does not prevent other CPUs from interfering with operations the first
CPU is performing
• Lock variables
• A single, shared (lock) variable, process sets it to 1 and enters the critical
region. If the lock is already 1, the process just waits until it becomes 0.
• Has the same fatal flaw that we saw in the spooler directory.

Based on Tanenbaum, Modern Operating Systems 3 e 24


Mutual Exclusion with Busy Waiting
• Strict alternation
• two processes strictly alternate in entering their critical regions
• it is not really a serious candidate as a solution because it violates condition 3
• Peterson's solution
• The TSL instruction

Based on Tanenbaum, Modern Operating Systems 3 e 25


Classical IPC Problems
• Producer–consumer problem
• Models access to a bounded-
buffer
• Producer won't try to add data
into the buffer if it's full
• Consumer won't try to remove
data from an empty buffer

Based on Tanenbaum, Modern Operating Systems 3 e 29


Classical IPC Problems
• Dining philosophers problem
(Dijkstra)
• Models processes competing for
exclusive access to a limited
number of resources such as I/O
devices

Based on Tanenbaum, Modern Operating Systems 3 e 30


Classical IPC Problems
• Readers–writers problem
• Models access to a database
• Two readers can read at once
• A writer should not wait longer
than needed
• Fairness for both readers and
writers

Based on Tanenbaum, Modern Operating Systems 3 e 31


Process Summary
• What are the units of execution?
• Processes
• How are those units of execution represented?
• Process Control Blocks (PCBs)
• How is work scheduled in the CPU?
• Process states, process queues, context switches
• What are the possible execution states of a process?
• Running, ready, waiting
• How does a process move from one state to another?
• Scheduling, I/O, creation, termination
• How are processes created?
• CreateProcess (Windows), fork/exec (Unix)

Based on Tanenbaum, Modern Operating Systems 3 e 32


Threads Summary
• The operating system as a large multithreaded program
• Each process executes as a thread within the OS
• Multithreading is very useful for applications
• Efficient multithreading requires fast primitives
• Processes are too heavyweight
• Solution is to separate threads from processes
• Kernel-level threads much better, but still significant overhead
• User-level threads even better, but not well integrated with OS

Based on Tanenbaum, Modern Operating Systems 3 e 33

You might also like