SlideShare a Scribd company logo
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Chapter 3: Processes
3.2 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Chapter 3: Processes
 Process Concept
 Process Scheduling
 Operations on Processes
 Interprocess Communication
 IPC in Shared-Memory Systems
 IPC in Message-Passing Systems
 Examples of IPC Systems
 Communication in Client-Server Systems
3.3 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Objectives
 Identify the separate components of a process and illustrate
how they are represented and scheduled in an operating
system.
 Describe how processes are created and terminated in an
operating system, including developing programs using the
appropriate system calls that perform these operations.
 Describe and contrast interprocess communication using
shared memory and message passing.
 Design programs that uses pipes and POSIX shared memory
to perform interprocess communication.
 Describe client-server communication using sockets and
remote procedure calls.
 Design kernel modules that interact with the Linux operating
system.
3.4 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Concept (Cont.)
 Program is passive entity stored on disk (executable file);
process is active
 Program becomes process when executable file loaded into
memory
 Execution of program 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
3.5 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Concept
 An operating system executes a variety of programs that run
as a process.
 Process – a program in execution; process execution must
progress in sequential fashion
 Multiple parts
 The program code, also called text section (The text
segment in a process structure primarily consists
of the executable code of the program, including
functions and instructions.)
 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 in Memory
3.6 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process in Memory
3.7 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Memory Layout of a C Program
3.8 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
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
3.9 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Diagram of Process State
3.10 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
There are several process states in operating system, they are:
• New State: When a process is first created or is initialized by the operating
system, it is in the new state. In this state, the process is being prepared to
enter the ready state.
• Ready State: When a process is ready to execute, it is in the ready state. In this
state, the process is waiting for the CPU to be allocated to it so that it can start
executing its instructions. A process can remain in the ready state for an
indeterminate period, waiting for the CPU to become available.
• Running State: When the CPU is allocated to a process, it enters the running
state. In this state, the process executes its instructions and uses system
resources such as memory, CPU, and I/O devices. Only one process can be in
the running state at a time, and the operating system determines which process
gets access to the CPU using scheduling algorithms.
• Waiting/Blocked State: Sometimes, a process needs to wait for a particular
event, such as user input or data from a disk drive. In such cases, the process
enters the blocked state. In this state, the process is not using the CPU, but it is
not ready to run either. The process remains in the blocked state until the event
it is waiting for occurs.
3.11 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
• Terminated State: The terminated state is reached when a process
completes its execution or terminates by the operating system. In this
state, the process no longer uses any system resources, and its
memory space is deallocated.
• Suspended State: When a process is temporarily removed from the
main memory and is stored on the disk to free up memory, it is said to
be in a suspended state. The process is not actively executing, and its
memory space is saved on the disk. When the process is needed again,
it is loaded back into the main memory and resumes execution.
3.12 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Control Block (PCB)
• A Process Control Block (PCB) is a data structure
used by an operating system to store all the
information about a process.
• It's like a "notebook" for each process, containing
details like the process's state, program counter,
register values, memory allocation, and
scheduling information.
• The PCB is crucial for efficient process
management, scheduling, and resource
allocation.
3.13 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Control Block (PCB)
Information associated with each process
(also called task control block)
 Process state – running, waiting, etc
 Program counter – location of instruction
to next execute
 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
3.14 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Control Block (PCB)
• A Process Control Block (PCB) is a data structure
used by an operating system to store all the
information about a process.
• It's like a "notebook" for each process, containing
details like the process's state, program counter,
register values, memory allocation, and
scheduling information.
• The PCB is crucial for efficient process
management, scheduling, and resource
allocation.
3.15 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Threads
 So far, process has a single thread of execution
 Consider having multiple program counters per process
 Multiple locations can execute at once
 Multiple threads of control -> threads
 Must then have storage for thread details, multiple program
counters in PCB
 Explore in detail in Chapter 4
3.16 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Representation in Linux
Represented by the C structure task_struct
pid t_pid; /* process identifier */
long state; /* state of the process */
unsigned int time_slice /* scheduling information */
struct task_struct *parent;/* this process’s parent */
struct list_head children; /* this process’s children */
struct files_struct *files;/* list of open files */
struct mm_struct *mm; /* address space of this process */
3.17 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Scheduling
 Maximize CPU use, quickly switch processes onto CPU core
 Process scheduler selects among available processes for
next execution on CPU core
 Maintains scheduling queues of processes
 Ready queue – set of all processes residing in main
memory, ready and waiting to execute
 Wait queues – set of processes waiting for an event (i.e.
I/O)
 Processes migrate among the various queues
3.18 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Ready and Wait Queues
3.19 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Representation of Process Scheduling
3.20 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
CPU Switch From Process to Process
A context switch occurs when the CPU
switches from one process to another.
3.21 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Context Switch
 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 via a context switch
 Context of a process represented in the PCB
 Context-switch time is overhead; the system does no useful
work while switching
 The more complex the OS and the PCB  the longer the
context switch
 Time dependent on hardware support
 Some hardware provides multiple sets of registers per CPU
 multiple contexts loaded at once
3.22 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Multitasking in Mobile Systems
 Some mobile systems (e.g., early version of iOS) allow only one
process to run, others suspended
 Due to screen real estate, user interface limits iOS provides for a
 Single foreground process- controlled via user interface
 Multiple background processes– in memory, running, but not
on the display, and with limits
 Limits include single, short task, receiving notification of events,
specific long-running tasks like audio playback
 Android runs foreground and background, with fewer limits
 Background process uses a service to perform tasks
 Service can keep running even if background process is
suspended
 Service has no user interface, small memory use
3.23 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Operations on Processes
 System must provide mechanisms for:
 process creation
 process termination
3.24 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Creation
 Parent process create children processes, which, in turn
create other processes, forming a tree of processes
 Generally, process identified and managed via a process
identifier (pid)
 Resource sharing options
 Parent and children share all resources
 Children share subset of parent’s resources
 Parent and child share no resources
 Execution options
 Parent and children execute concurrently
 Parent waits until children terminate
3.25 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
A Tree of Processes in Linux
3.26 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Creation (Cont.)
 Address space
 Child duplicate of parent
 Child has a program loaded into it
 UNIX examples
 fork() system call creates new process
 exec() system call used after a fork() to replace the
process’ memory space with a new program
 Parent process calls wait() for the child to terminate
3.27 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
C Program Forking Separate Process
3.28 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Creating a Separate Process via Windows API
3.29 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Termination
 Process executes last statement and then asks the operating
system to delete it using the exit() system call.
 Returns status data from child to parent (via wait())
 Process’ resources are deallocated by operating system
 Parent may terminate the execution of children processes using
the abort() system call. Some reasons for doing so:
 Child has exceeded allocated resources
 Task assigned to child is no longer required
 The parent is exiting and the operating systems does not
allow a child to continue if its parent terminates
3.30 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Process Termination
 Some operating systems do not allow child to exists if its parent has
terminated. If a process terminates, then all its children must also
be terminated.
 cascading termination. All children, grandchildren, etc. are
terminated.
 The termination is initiated by the operating system.
 The parent process may wait for termination of a child process by
using the wait()system call. The call returns status information
and the pid of the terminated process
pid = wait(&status);
 If no parent waiting (did not invoke wait()) process is a zombie
 If parent terminated without invoking wait , process is an orphan
3.31 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Android Process Importance Hierarchy
 Mobile operating systems often have to terminate processes to reclaim
system resources such as memory. From most to least important:
o Foreground process
o Visible process
o Service process
o Background process
o Empty process
 Android will begin terminating processes that are least important.
3.32 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Multiprocess Architecture – Chrome Browser
 Many web browsers ran as single process (some still do)
 If one web site causes trouble, entire browser can hang or crash
 Google Chrome Browser is multiprocess with 3 different types of
processes:
 Browser process manages user interface, disk and network I/O
 Renderer process renders web pages, deals with HTML,
Javascript. A new renderer created for each website opened
 Runs in sandbox restricting disk and network I/O, minimizing
effect of security exploits
 Plug-in process for each type of plug-in
3.33 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Interprocess Communication
 Processes within a system may be independent or cooperating
 Cooperating process can affect or be affected by other processes,
including sharing data
 Reasons for cooperating processes:
 Information sharing
 Computation speedup
 Modularity
 Convenience
 Cooperating processes need interprocess communication (IPC)
 Two models of IPC
 Shared memory
 Message passing
3.34 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Communications Models
(a) Shared memory. (b) Message passing.
3.35 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Cooperating Processes
 Independent process cannot affect or be affected by the execution
of another process
 Cooperating process can affect or be affected by the execution of
another process
 Advantages of process cooperation
 Information sharing
 Computation speed-up
 Modularity
 Convenience
3.36 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Producer-Consumer Problem
 Paradigm for cooperating processes, producer process
produces information that is consumed by a consumer
process
 unbounded-buffer places no practical limit on the size
of the buffer
 bounded-buffer assumes that there is a fixed buffer
size
3.37 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Interprocess Communication – Shared Memory
 An area of memory shared among the processes that wish
to communicate
 The communication is under the control of the users
processes not the operating system.
 Major issues is to provide mechanism that will allow the
user processes to synchronize their actions when they
access shared memory.
 Synchronization is discussed in great details in Chapters 6
& 7.
3.38 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Bounded-Buffer – Shared-Memory Solution
 Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
 Solution is correct, but can only use BUFFER_SIZE-1 elements
3.39 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Producer Process – Shared Memory
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
3.40 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Consumer Process – Shared Memory
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
/* consume the item in next consumed */
}
3.41 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Interprocess Communication – Message Passing
 Mechanism for processes to communicate and to synchronize
their actions
 Message system – processes communicate with each other
without resorting to shared variables
 IPC facility provides two operations:
 send(message)
 receive(message)
 The message size is either fixed or variable
3.42 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Message Passing (Cont.)
 If processes P and Q wish to communicate, they need to:
 Establish a communication link between them
 Exchange messages via send/receive
 Implementation issues:
 How are links established?
 Can a link be associated with more than two processes?
 How many links can there be between every pair of
communicating processes?
 What is the capacity of a link?
 Is the size of a message that the link can accommodate fixed or
variable?
 Is a link unidirectional or bi-directional?
3.43 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Message Passing (Cont.)
 Implementation of communication link
 Physical:
 Shared memory
 Hardware bus
 Network
 Logical:
 Direct or indirect
 Synchronous or asynchronous
 Automatic or explicit buffering
3.44 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
Direct Communication
 Processes must name each other explicitly:
 send (P, message) – send a message to process P
 receive(Q, message) – receive a message from process Q
 Properties of communication link
 Links are established automatically
 A link is associated with exactly one pair of communicating
processes
 Between each pair there exists exactly one link
 The link may be unidirectional, but is usually bi-directional
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th
Edition
End of Chapter 3

More Related Content

PPTX
ch03.pptx
PPT
Chapter 3-Processes userd in operating sys.ppt
PPT
2.ch3 Process (1).ppt
PDF
Unit II - 1 - Operating System Process
PPT
Unit 2-ch3-Processes in Operating Systems
PPT
chapter 2 name:- operating System Processes
PPT
CPU Process Synchronization (Chapter 3).pptx
PPTX
ch3.pptx
ch03.pptx
Chapter 3-Processes userd in operating sys.ppt
2.ch3 Process (1).ppt
Unit II - 1 - Operating System Process
Unit 2-ch3-Processes in Operating Systems
chapter 2 name:- operating System Processes
CPU Process Synchronization (Chapter 3).pptx
ch3.pptx

Similar to Module-2 presentation.ppt of embedded system (20)

PPTX
ch3_LU6_LU7_Lecture_1691052564579.pptx
PPTX
Processes
PPTX
ch3.pptx
PDF
os-ch03.pdfEGERGQEGQERGQEGQERGQERGQERGQERG
PPT
process management.ppt
PPT
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
PPT
ch3.ppt
PPT
Lecture_Process.ppt
PPTX
cs8493 - operating systems unit 2
PPT
ch3 (1).ppt
PPT
PPT
ch3 s ppt
PPT
ch3.ppt
PPT
Operating System
PPT
Processes
PPTX
Chapter 3 Processes (1)Operating systems.pptx
PPTX
Week03-Ch3-Process Concept.pptx.gfhgvjhg
PDF
3 processes
PPTX
14712-l4.pptx
PPT
Chapter 3: Processes
ch3_LU6_LU7_Lecture_1691052564579.pptx
Processes
ch3.pptx
os-ch03.pdfEGERGQEGQERGQEGQERGQERGQERGQERG
process management.ppt
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3.ppt
Lecture_Process.ppt
cs8493 - operating systems unit 2
ch3 (1).ppt
ch3 s ppt
ch3.ppt
Operating System
Processes
Chapter 3 Processes (1)Operating systems.pptx
Week03-Ch3-Process Concept.pptx.gfhgvjhg
3 processes
14712-l4.pptx
Chapter 3: Processes
Ad

Recently uploaded (20)

PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
Current and future trends in Computer Vision.pptx
PPT
Occupational Health and Safety Management System
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
737-MAX_SRG.pdf student reference guides
PPTX
UNIT - 3 Total quality Management .pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
R24 SURVEYING LAB MANUAL for civil enggi
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Fundamentals of Mechanical Engineering.pptx
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Current and future trends in Computer Vision.pptx
Occupational Health and Safety Management System
Exploratory_Data_Analysis_Fundamentals.pdf
Soil Improvement Techniques Note - Rabbi
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
737-MAX_SRG.pdf student reference guides
UNIT - 3 Total quality Management .pptx
Ad

Module-2 presentation.ppt of embedded system

  • 1. Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Chapter 3: Processes
  • 2. 3.2 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Chapter 3: Processes  Process Concept  Process Scheduling  Operations on Processes  Interprocess Communication  IPC in Shared-Memory Systems  IPC in Message-Passing Systems  Examples of IPC Systems  Communication in Client-Server Systems
  • 3. 3.3 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Objectives  Identify the separate components of a process and illustrate how they are represented and scheduled in an operating system.  Describe how processes are created and terminated in an operating system, including developing programs using the appropriate system calls that perform these operations.  Describe and contrast interprocess communication using shared memory and message passing.  Design programs that uses pipes and POSIX shared memory to perform interprocess communication.  Describe client-server communication using sockets and remote procedure calls.  Design kernel modules that interact with the Linux operating system.
  • 4. 3.4 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Concept (Cont.)  Program is passive entity stored on disk (executable file); process is active  Program becomes process when executable file loaded into memory  Execution of program 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
  • 5. 3.5 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Concept  An operating system executes a variety of programs that run as a process.  Process – a program in execution; process execution must progress in sequential fashion  Multiple parts  The program code, also called text section (The text segment in a process structure primarily consists of the executable code of the program, including functions and instructions.)  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 in Memory
  • 6. 3.6 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process in Memory
  • 7. 3.7 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Memory Layout of a C Program
  • 8. 3.8 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 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
  • 9. 3.9 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Diagram of Process State
  • 10. 3.10 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition There are several process states in operating system, they are: • New State: When a process is first created or is initialized by the operating system, it is in the new state. In this state, the process is being prepared to enter the ready state. • Ready State: When a process is ready to execute, it is in the ready state. In this state, the process is waiting for the CPU to be allocated to it so that it can start executing its instructions. A process can remain in the ready state for an indeterminate period, waiting for the CPU to become available. • Running State: When the CPU is allocated to a process, it enters the running state. In this state, the process executes its instructions and uses system resources such as memory, CPU, and I/O devices. Only one process can be in the running state at a time, and the operating system determines which process gets access to the CPU using scheduling algorithms. • Waiting/Blocked State: Sometimes, a process needs to wait for a particular event, such as user input or data from a disk drive. In such cases, the process enters the blocked state. In this state, the process is not using the CPU, but it is not ready to run either. The process remains in the blocked state until the event it is waiting for occurs.
  • 11. 3.11 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition • Terminated State: The terminated state is reached when a process completes its execution or terminates by the operating system. In this state, the process no longer uses any system resources, and its memory space is deallocated. • Suspended State: When a process is temporarily removed from the main memory and is stored on the disk to free up memory, it is said to be in a suspended state. The process is not actively executing, and its memory space is saved on the disk. When the process is needed again, it is loaded back into the main memory and resumes execution.
  • 12. 3.12 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Control Block (PCB) • A Process Control Block (PCB) is a data structure used by an operating system to store all the information about a process. • It's like a "notebook" for each process, containing details like the process's state, program counter, register values, memory allocation, and scheduling information. • The PCB is crucial for efficient process management, scheduling, and resource allocation.
  • 13. 3.13 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Control Block (PCB) Information associated with each process (also called task control block)  Process state – running, waiting, etc  Program counter – location of instruction to next execute  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
  • 14. 3.14 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Control Block (PCB) • A Process Control Block (PCB) is a data structure used by an operating system to store all the information about a process. • It's like a "notebook" for each process, containing details like the process's state, program counter, register values, memory allocation, and scheduling information. • The PCB is crucial for efficient process management, scheduling, and resource allocation.
  • 15. 3.15 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Threads  So far, process has a single thread of execution  Consider having multiple program counters per process  Multiple locations can execute at once  Multiple threads of control -> threads  Must then have storage for thread details, multiple program counters in PCB  Explore in detail in Chapter 4
  • 16. 3.16 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Representation in Linux Represented by the C structure task_struct pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent;/* this process’s parent */ struct list_head children; /* this process’s children */ struct files_struct *files;/* list of open files */ struct mm_struct *mm; /* address space of this process */
  • 17. 3.17 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Scheduling  Maximize CPU use, quickly switch processes onto CPU core  Process scheduler selects among available processes for next execution on CPU core  Maintains scheduling queues of processes  Ready queue – set of all processes residing in main memory, ready and waiting to execute  Wait queues – set of processes waiting for an event (i.e. I/O)  Processes migrate among the various queues
  • 18. 3.18 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Ready and Wait Queues
  • 19. 3.19 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Representation of Process Scheduling
  • 20. 3.20 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition CPU Switch From Process to Process A context switch occurs when the CPU switches from one process to another.
  • 21. 3.21 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Context Switch  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 via a context switch  Context of a process represented in the PCB  Context-switch time is overhead; the system does no useful work while switching  The more complex the OS and the PCB  the longer the context switch  Time dependent on hardware support  Some hardware provides multiple sets of registers per CPU  multiple contexts loaded at once
  • 22. 3.22 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Multitasking in Mobile Systems  Some mobile systems (e.g., early version of iOS) allow only one process to run, others suspended  Due to screen real estate, user interface limits iOS provides for a  Single foreground process- controlled via user interface  Multiple background processes– in memory, running, but not on the display, and with limits  Limits include single, short task, receiving notification of events, specific long-running tasks like audio playback  Android runs foreground and background, with fewer limits  Background process uses a service to perform tasks  Service can keep running even if background process is suspended  Service has no user interface, small memory use
  • 23. 3.23 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Operations on Processes  System must provide mechanisms for:  process creation  process termination
  • 24. 3.24 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Creation  Parent process create children processes, which, in turn create other processes, forming a tree of processes  Generally, process identified and managed via a process identifier (pid)  Resource sharing options  Parent and children share all resources  Children share subset of parent’s resources  Parent and child share no resources  Execution options  Parent and children execute concurrently  Parent waits until children terminate
  • 25. 3.25 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition A Tree of Processes in Linux
  • 26. 3.26 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Creation (Cont.)  Address space  Child duplicate of parent  Child has a program loaded into it  UNIX examples  fork() system call creates new process  exec() system call used after a fork() to replace the process’ memory space with a new program  Parent process calls wait() for the child to terminate
  • 27. 3.27 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition C Program Forking Separate Process
  • 28. 3.28 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Creating a Separate Process via Windows API
  • 29. 3.29 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Termination  Process executes last statement and then asks the operating system to delete it using the exit() system call.  Returns status data from child to parent (via wait())  Process’ resources are deallocated by operating system  Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so:  Child has exceeded allocated resources  Task assigned to child is no longer required  The parent is exiting and the operating systems does not allow a child to continue if its parent terminates
  • 30. 3.30 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Process Termination  Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated.  cascading termination. All children, grandchildren, etc. are terminated.  The termination is initiated by the operating system.  The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status);  If no parent waiting (did not invoke wait()) process is a zombie  If parent terminated without invoking wait , process is an orphan
  • 31. 3.31 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Android Process Importance Hierarchy  Mobile operating systems often have to terminate processes to reclaim system resources such as memory. From most to least important: o Foreground process o Visible process o Service process o Background process o Empty process  Android will begin terminating processes that are least important.
  • 32. 3.32 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Multiprocess Architecture – Chrome Browser  Many web browsers ran as single process (some still do)  If one web site causes trouble, entire browser can hang or crash  Google Chrome Browser is multiprocess with 3 different types of processes:  Browser process manages user interface, disk and network I/O  Renderer process renders web pages, deals with HTML, Javascript. A new renderer created for each website opened  Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits  Plug-in process for each type of plug-in
  • 33. 3.33 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Interprocess Communication  Processes within a system may be independent or cooperating  Cooperating process can affect or be affected by other processes, including sharing data  Reasons for cooperating processes:  Information sharing  Computation speedup  Modularity  Convenience  Cooperating processes need interprocess communication (IPC)  Two models of IPC  Shared memory  Message passing
  • 34. 3.34 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Communications Models (a) Shared memory. (b) Message passing.
  • 35. 3.35 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Cooperating Processes  Independent process cannot affect or be affected by the execution of another process  Cooperating process can affect or be affected by the execution of another process  Advantages of process cooperation  Information sharing  Computation speed-up  Modularity  Convenience
  • 36. 3.36 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Producer-Consumer Problem  Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process  unbounded-buffer places no practical limit on the size of the buffer  bounded-buffer assumes that there is a fixed buffer size
  • 37. 3.37 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Interprocess Communication – Shared Memory  An area of memory shared among the processes that wish to communicate  The communication is under the control of the users processes not the operating system.  Major issues is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory.  Synchronization is discussed in great details in Chapters 6 & 7.
  • 38. 3.38 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Bounded-Buffer – Shared-Memory Solution  Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0;  Solution is correct, but can only use BUFFER_SIZE-1 elements
  • 39. 3.39 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Producer Process – Shared Memory item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; }
  • 40. 3.40 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Consumer Process – Shared Memory item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ }
  • 41. 3.41 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Interprocess Communication – Message Passing  Mechanism for processes to communicate and to synchronize their actions  Message system – processes communicate with each other without resorting to shared variables  IPC facility provides two operations:  send(message)  receive(message)  The message size is either fixed or variable
  • 42. 3.42 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Message Passing (Cont.)  If processes P and Q wish to communicate, they need to:  Establish a communication link between them  Exchange messages via send/receive  Implementation issues:  How are links established?  Can a link be associated with more than two processes?  How many links can there be between every pair of communicating processes?  What is the capacity of a link?  Is the size of a message that the link can accommodate fixed or variable?  Is a link unidirectional or bi-directional?
  • 43. 3.43 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Message Passing (Cont.)  Implementation of communication link  Physical:  Shared memory  Hardware bus  Network  Logical:  Direct or indirect  Synchronous or asynchronous  Automatic or explicit buffering
  • 44. 3.44 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition Direct Communication  Processes must name each other explicitly:  send (P, message) – send a message to process P  receive(Q, message) – receive a message from process Q  Properties of communication link  Links are established automatically  A link is associated with exactly one pair of communicating processes  Between each pair there exists exactly one link  The link may be unidirectional, but is usually bi-directional
  • 45. Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition End of Chapter 3