SlideShare a Scribd company logo
1 of 70
Download to read offline
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts
Chapter 3: Processes
2
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Chapter 3: Processes
q Process Concept
q Process Scheduling
q Operations on Processes
q Inter-Process Communication (IPC)
q IPC in Shared-Memory Systems
q IPC in Message-Passing Systems
q Examples of IPC Systems
q Communication in Client-Server Systems
3
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Objectives
q Identify the separate components of a process and illustrate how they
are represented and scheduled in an operating system.
q Describe how processes are created and terminated in an operating
system, including developing programs using the appropriate system
calls that perform these operations.
q Describe and contrast inter-process communication using shared
memory and message passing.
q Design programs that uses pipes and POSIX shared memory to
perform inter-process communication.
q Describe client-server communication using sockets and remote
procedure calls.
q Design kernel modules that interact with the Linux operating system.
4
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Concept
q An operating system executes a variety of programs that run as
processes
q Process – a program in execution; process execution must progress
in sequential fashion
q Multiple parts
o The program code, also called text section
o Current activity including program counter, and processor registers
o Stack section containing temporary data
4 Function parameters, return addresses, local variables
o Data section containing global variables
o Heap section containing memory dynamically allocated during run time
5
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Concept (Cont.)
q Program is passive entity stored on disk (e.g., executable file)
q Process is active entity
o Program becomes process when executable file loaded into memory
q Execution of program can be started via GUI mouse clicks, command
line (CLI) entry of its name, etc.
q One program can be several processes
o E.g., Consider multiple users executing the same program
#ps -aux
6
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process in Memory
(memory limits of a process)
#size <pid>
7
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Memory Layout of a C Program
8
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process State
q As a process executes, it changes state
o New – The process is being created
o Running – Instructions are being executed
o Waiting – The process is waiting for some event to occur
o Ready – The process is waiting to be assigned to a processor
o Terminated – The process has finished execution
9
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Diagram of Process State
10
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Control Block (PCB)
q Process Control Block (PCB) – Information associated with
each process, also called Task Control Block (TCB), includes:
o Process state – running, waiting, etc.
o Process number – identity of the process
o Program counter – location of instruction to next execute
o CPU registers – contents of all process-centric registers
o CPU scheduling info – priorities, scheduling queue pointers
o Memory-management information – memory allocated to the
process
o Accounting information – CPU used, clock time elapsed
since start, time limits
o I/O status information – I/O devices allocated to process, list of
open files
11
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Threads
q So far, process has a single thread of execution
q Consider having multiple program counters per process
o Multiple locations can execute at once
4 Multiple threads of control –> threads
q Must then have storage for thread details
q Multiple program counters in PCB
(Explore in detail in Chapter 4)
12
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Representation in Linux
q 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 */
13
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Scheduling
q Maximize CPU use ⇢ quickly switch processes onto CPU core
q Process scheduler selects one process among available (ready)
processes for next execution on CPU core
q Maintains scheduling queues of processes
o Ready queue – set of all processes residing in main memory, ready and
waiting to execute
o Wait queues – set of processes waiting for an event (e.g., I/O)
q Processes migrate among the various queues
14
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Ready and Wait Queues
15
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Representation of Process Scheduling
new process
16
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
CPU Switch from Process to Process
q A context switch
occurs when the
CPU switches
from one process
to another.
17
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Context Switch
q 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
q Context of a process represented in the PCB
q Context-switch time is overhead, the system does no useful work
while switching
o The more complex the OS and the PCB, the longer the context switch
q Time dependent on hardware support
o Some hardware provides multiple sets of registers per CPU, multiple
contexts loaded at once
18
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Multitasking in Mobile Systems
q Some mobile systems (e.g., early version of iOS) allow only one
process to run, others suspended
q Due to screen real state, user interface limits iOS provides for a
o Single foreground process – controlled via user interface
o Multiple background processes – in memory, running, but not on the
display, and with limits
o Limits include single, short task, receiving notification of events, specific
long-running tasks like audio playback
q Android runs foreground and background, with fewer limits
o Background process uses a service to perform tasks
o Service can keep running even if background process is suspended
o Service has no user interface, small memory use
19
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Operations on Processes
q System must provide mechanisms for:
o process creation
o process termination
20
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Creation
q Parent processes create children processes, which, in turn create
other processes, forming a tree of processes
q Process identified and managed via a Process Identifier (PID)
q Resource sharing options
o Parent and children share all resources
o Children share subset of parent’s resources
o Parent and child share no resources
21
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Creation (Cont.)
q Execution options
o Parent and children execute concurrently
o Parent waits until children terminate
q Address space
o Child duplicate of parent
o Child has a program loaded into it
22
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
A Tree of Processes in Linux
#pstree
23
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Creation (Cont.)
q UNIX examples
o fork() system call creates new process
o exec() system call used after a fork() to replace the process’
memory space with a new program
o Parent process calls wait() waiting for the child to terminate
24
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
C Program Forking A Separate Process
25
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Creating a Separate Process via Windows API
26
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Termination
q Process executes last statement and then asks the operating system
to delete it using the exit() system call.
o Returns status data from child to parent (via wait())
o Process’resources are deallocated by operating system
q Parent may terminate the execution of children processes using the
abort() system call. Some reasons for doing so:
o Child has exceeded allocated resources
o Task assigned to child is no longer required
o The parent is exiting and the operating systems does not allow a child to
continue if its parent terminates
27
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Process Termination (Cont.)
q 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.
o Cascading termination: All children, grandchildren, etc. are terminated
o The termination is initiated by the operating system
q 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);
q If no parent waiting (did not invoke wait()), process is a zombie
q If parent terminated without invoking wait(), process is an orphan
28
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Importance Hierarchy of Android Process
q Mobile operating systems often have to terminate processes to
reclaim system resources such as memory. From most to least
important:
▲ Foreground process
▲ Visible process
▲ Service process
▲ Background process
▲ Empty process
q Android will begin terminating processes that are least important.
29
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Multiprocess Architecture – Chrome Browser
q Many web browsers ran as a single process (some still do)
o If one web site causes trouble, entire browser can hang or crash
q Google Chrome Browser is multiprocess with 3 different types of
processes:
o Browser process manages user interface, disk and network I/O
o Renderer process renders web pages, deals with HTML, JavaScript. A
new renderer created for each website opened
4 Runs in sandbox restricting disk and network I/O, minimizing effect of security
exploits
o Plug-in process for each type of plug-in
30
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Inter-Process Communication (IPC)
q Processes within a system may be independent or cooperating
o Independent process does not share data with any other processes
executing in the system
o Cooperating process can affect or be affected by other processes,
including sharing data
q Reasons for cooperating processes:
o Information sharing
o Computation speed-up
o Modularity
o Convenience
q Cooperating processes need Inter-Process communication (IPC)
31
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Communication Models
q Two models of IPC
o Shared memory
o Message passing
Shared memory Message passing
32
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Inter-Process Communication – Shared Memory
q An area of memory shared among the processes that wish to
communicate
q The communication is under the control of the users processes, not
the operating system.
q 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)
33
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Producer-Consumer Problem
q Producer-Consumer relationship
q Paradigm for cooperating processes, producer process produces
information that is consumed by a consumer process
o unbounded-buffer places no practical limit on the size of the buffer
o bounded-buffer assumes that there is a fixed buffer size
34
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Bounded-Buffer – Shared-Memory Solution
q Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
q Solution is correct, but can only use BUFFER_SIZE-1 elements
35
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
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;
}
36
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
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 */
}
37
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Inter-Process Communication – Message
Passing
q Mechanism for processes to communicate and to synchronize their
actions
q Message system – processes communicate with each other without
resorting to shared variables
q IPC facility provides two operations:
o send(message)
o receive(message)
q The message size is either fixed or variable
38
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Message Passing (Cont.)
q If processes P and Q wish to communicate, they need to:
o Establish a communication link between them
o Exchange messages via send/receive
q Implementation issues:
o How are links established?
o Can a link be associated with more than two processes?
o How many links can there be between every pair of communicating
processes?
o What is the capacity of a link?
o Is the size of a message that the link can accommodate fixed or variable?
o Is a link unidirectional or bi-directional?
39
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Message Passing (Cont.)
q Implementation of communication link
o Physical
4 Shared memory
4 Hardware bus
4 Network equipment
o Logical
4 Direct or indirect
4 Synchronous or asynchronous
4 Automatic or explicit buffering
4 Network protocols
40
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Direct Communication
q Processes must name each other explicitly:
o send (P, message) – send a message to process P
o receive(Q, message) – receive a message from process Q
q Properties of communication link
o Links are established automatically
o A link is associated with exactly one pair of communicating processes
o Between each pair there exists exactly one link
o The link may be unidirectional, but is usually bi-directional
41
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Indirect Communication
q Messages are directed and received from mailboxes (also referred to
as ports)
o Each mailbox has a unique ID
o Processes can communicate only if they share a mailbox
q Properties of communication link
o Link established only if processes share a common mailbox
o A link may be associated with many processes
o Each pair of processes may share several communication links
o Link may be unidirectional or bi-directional
42
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Indirect Communication (Cont.)
q Operations
o create a new mailbox (or port)
o send and receive messages through mailbox
o destroy a mailbox
q Primitives are defined as:
o send(A, message) – send a message to mailbox A
o receive(A, message) – receive a message from mailbox A
43
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Indirect Communication (Cont.)
q Mailbox sharing
o Example
4 P1, P2, and P3 share mailbox A,
4 P1 sends; P2 and P3 receive.
4 Who gets the message?
o Solutions
4 Allow a link to be associated with at most two processes
4 Allow only one process at a time to execute a receive operation
4 Allow the system to select arbitrarily the receiver. Sender is notified who the
receiver was
44
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Message Passing – Synchronization
q Message passing may be either blocking or non-blocking
q Blocking is considered synchronous
o Blocking send – the sender is blocked until the message is received
o Blocking receive – the receiver is blocked until a message is available
q Non-blocking is considered asynchronous
o Non-blocking send – the sender sends the message and continue
o Non-blocking receive – the receiver receives:
4 A valid message, or Null message
q Different combinations possible
o If both send and receive are blocking, we have a rendezvous
45
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Producer – Message Passing
message next_produced;
while (true) {
/* produce an item in next_produced */
send(next_produced);
}
46
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Consumer – Message Passing
message next_consumed;
while (true) {
receive(next_consumed)
/* consume the item in next_consumed */
}
47
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Buffering
q Queue of messages attached to the link.
q Implemented in one of three ways
o Zero capacity – no messages are queued on a link
4 Sender must wait for receiver (rendezvous)
o Bounded capacity – finite length of n messages
4 Sender must wait if link full
o Unbounded capacity – infinite length
4 Sender never waits
48
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - POSIX
q POSIX Shared Memory
o Process first creates shared memory segment
shm_fd = shm_open(name, O CREAT | O RDWR, 0666);
o Also used to open an existing segment
o Set the size of the object
ftruncate(shm_fd, 4096);
o Use mmap() to memory-map a file pointer to the shared memory object
o Reading and writing to shared memory is done by using the pointer
returned by mmap().
49
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
IPC POSIX Producer – Consumer
50
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - Mach
q Mach communication is message based
o Even system calls are messages
o Each task gets two ports at creation – Task Self port and Notify port
o Messages are sent and received using the mach_msg() function
o Ports needed for communication, created via mach_port_allocate()
o Send and receive are flexible, for example four options if mailbox full:
4 Wait indefinitely
4 Wait at most n milliseconds
4 Return immediately
4 Temporarily cache a message
51
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Mach Messages
#include<mach/mach.h>
struct message {
mach_msg_header_t header;
int data;
};
mach port t client;
mach port t server;
52
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Mach Message Passing - Client
53
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Mach Message Passing - Server
54
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems – Windows
q Message-passing centric via advanced Local Procedure Call (LPC)
facility
o Only works between processes on the same system
o Uses ports (like mailboxes) to establish and maintain communication
channels
o Communication works as follows:
4 The client opens a handle to the subsystem’s connection port object
4 The client sends a connection request
4 The server creates two private communication ports and returns the handle to
one of them to the client
4 The client and server use the corresponding port handle to send messages or
callbacks and to listen for replies
55
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Local Procedure Calls in Windows
56
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Pipes
q Acts as a conduit allowing two processes to communicate
q Issues:
o Is communication unidirectional or bidirectional?
o In the case of two-way communication, is it half or full-duplex?
o Must there exist a relationship (e.g., parent-child) between the
communicating processes?
o Can the pipes be used over a network?
q Ordinary pipes – cannot be accessed from outside the process that
created it. Typically, a parent process creates a pipe and uses it to
communicate with a child process that it created.
q Named pipes – can be accessed without a parent-child relationship.
57
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Ordinary Pipes
q Ordinary Pipes allow communication in standard producer-consumer
style
o Producer writes to one end (the write-end of the pipe)
o Consumer reads from the other end (the read-end of the pipe)
q Ordinary pipes are therefore unidirectional
q Require parent-child relationship between communicating processes
58
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Named Pipes
q Named pipes are more powerful than ordinary pipes
q Communication is bidirectional
q No parent-child relationship is necessary between the communicating
processes
q Several processes can use the named pipe for communication
q Provided on both UNIX and Windows systems
59
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Communications in Client-Server Systems
q Sockets
o A socket is defined as an endpoint for communication
o It is a concatenation of IP address and port – a number included at start
of message packet to differentiate network services on a host
4 E.g., The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
o Communication consists between a pair of sockets
o All ports below 1024 are well known, used for standard services
o Special IP address 127.0.0.1 (loopback) to refer to system on which
process is running
q Remote Procedure Calls (RPC)
60
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Socket Communication
61
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Sockets in Java – Server
q Three types of sockets
o Connection-oriented
(TCP)
o Connectionless
(UDP)
o MulticastSocket
class– data can be
sent to multiple
recipients
q Consider this “Date”
server in Java:
62
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Sockets in Java – Client
q The equivalent
“Date” client
63
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Remote Procedure Calls
q Remote Procedure Call (RPC) abstracts procedure calls between
processes on networked systems
o Again uses ports for service differentiation
q Stubs – proxies for the actual procedure on the server and client
sides
o The client-side stub locates the server and marshals the parameters
o The server-side stub receives this message, unpacks the marshalled
parameters, and performs the procedure on the server
q On Windows, stub code compile from specification written in
Microsoft Interface Definition Language (MIDL)
64
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Remote Procedure Calls (Cont.)
q Data representation handled via External Data Representation
(XDR) format to account for different architectures
o E.g., Big-endian (Motorola) and little-endian (Intel x86)
q Remote communication has more failure scenarios than local
o Messages can be delivered exactly once rather than at most once
q OS typically provides a rendezvous (or matchmaker) service to
connect client and server
65
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Execution of RPC
66
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Summary
q A process is a program in execution, and the status of the current
activity of a process is represented by the program counter, as well
as other registers.
q The layout of a process in memory is represented by four different
sections: (1) text, (2) data, (3) heap, and (4) stack.
q As a process executes, it changes state. There are four general
states of a process: (1) ready, (2) running, (3) waiting, and (4)
terminated.
q A process control block (PCB) is the kernel data structure that
represents a process in an operating system.
q The role of the process scheduler is to select an available process
to run on a CPU.
67
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Summary (Cont.)
q An operating system performs a context switch when it switches
from running one process to running another.
q The fork() and CreateProcess() system calls are used to
create processes on UNIX and Windows systems, respectively.
q When shared memory is used for communication between
processes, two (or more) processes share the same region of
memory. POSIX provides an API for shared memory.
q Two processes may communicate by exchanging messages with one
another using message passing. The Mach operating system uses
message passing as its primary form of inter-process communication.
Windows provides a form of message passing as well.
68
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Summary (Cont.)
q A pipe provides a conduit for two processes to communicate. There
are two forms of pipes, ordinary and named. Ordinary pipes are
designed for communication between processes that have a parent-
child relationship. Named pipes are more general and allow several
processes to communicate.
q UNIX systems provide ordinary pipes through the pipe() system
call. Ordinary pipes have a read end and a write end. A parent
process can, for example, send data to the pipe using its write end,
and the child process can read it from its read end. Named pipes in
UNIX are termed FIFOs.
69
Operating System Concepts Silberschatz, Galvin and Gagne ©2018
Summary (Cont.)
q Windows systems also provide two forms of pipes—anonymous and
named pipes. Anonymous pipes are similar to UNIX ordinary pipes.
They are unidirectional and employ parent-child relationships
between the communicating processes. Named pipes offer a richer
form of inter-process communication than the UNIX counterpart,
FIFOs.
q Two common forms of client-server communication are sockets
and remote procedure calls (RPCs). Sockets allow two processes on
different machines to communicate over a network. RPCs abstract
the concept of function (procedure) calls in such a way that a function
can be invoked on another process that may reside on a separate
computer.
q The Android operating system uses RPCs as a form of inter-process
communication using its binder framework.
Silberschatz, Galvin and Gagne ©2018
Operating System Concepts
End of Chapter 3

More Related Content

Similar to ch3_EN_BK_Process.pdf

Similar to ch3_EN_BK_Process.pdf (20)

2.ch3 Process (1).ppt
2.ch3 Process (1).ppt2.ch3 Process (1).ppt
2.ch3 Process (1).ppt
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Process
 
ch3-lect7.pptx
ch3-lect7.pptxch3-lect7.pptx
ch3-lect7.pptx
 
Lecture 8 9 process_concept
Lecture 8 9 process_conceptLecture 8 9 process_concept
Lecture 8 9 process_concept
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3 (1).ppt
ch3 (1).pptch3 (1).ppt
ch3 (1).ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Lecture_Process.ppt
Lecture_Process.pptLecture_Process.ppt
Lecture_Process.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3 s ppt
ch3 s                                  pptch3 s                                  ppt
ch3 s ppt
 
cs8493 - operating systems unit 2
cs8493 - operating systems unit 2cs8493 - operating systems unit 2
cs8493 - operating systems unit 2
 
Processes
ProcessesProcesses
Processes
 
Operating System
Operating SystemOperating System
Operating System
 
process management.ppt
process management.pptprocess management.ppt
process management.ppt
 
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
 
ch4_EN_BK_Threads.pdf
ch4_EN_BK_Threads.pdfch4_EN_BK_Threads.pdf
ch4_EN_BK_Threads.pdf
 
3 processes
3 processes3 processes
3 processes
 

More from HoNguyn746501

More from HoNguyn746501 (10)

ch2_EN_BK.pdf
ch2_EN_BK.pdfch2_EN_BK.pdf
ch2_EN_BK.pdf
 
ch10_massSt.pdf
ch10_massSt.pdfch10_massSt.pdf
ch10_massSt.pdf
 
ch9_virMem.pdf
ch9_virMem.pdfch9_virMem.pdf
ch9_virMem.pdf
 
ch11_fileInterface.pdf
ch11_fileInterface.pdfch11_fileInterface.pdf
ch11_fileInterface.pdf
 
ch5_EN_CPUSched.pdf
ch5_EN_CPUSched.pdfch5_EN_CPUSched.pdf
ch5_EN_CPUSched.pdf
 
ch12_fileImplementation.pdf
ch12_fileImplementation.pdfch12_fileImplementation.pdf
ch12_fileImplementation.pdf
 
ch8_mainMem.pdf
ch8_mainMem.pdfch8_mainMem.pdf
ch8_mainMem.pdf
 
ch7_EN_BK_sync2.pdf
ch7_EN_BK_sync2.pdfch7_EN_BK_sync2.pdf
ch7_EN_BK_sync2.pdf
 
ch6_EN_BK_syn1.pdf
ch6_EN_BK_syn1.pdfch6_EN_BK_syn1.pdf
ch6_EN_BK_syn1.pdf
 
ch1_EN_BK-2.pdf
ch1_EN_BK-2.pdfch1_EN_BK-2.pdf
ch1_EN_BK-2.pdf
 

Recently uploaded

FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | DelhiFULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhisoniya singh
 
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai Gaped
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai GapedCall Girls Dubai Slut Wife O525547819 Call Girls Dubai Gaped
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai Gapedkojalkojal131
 
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一ga6c6bdl
 
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberCall Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberMs Riya
 
Book Sex Workers Available Pune Call Girls Yerwada 6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Yerwada  6297143586 Call Hot India...Book Sex Workers Available Pune Call Girls Yerwada  6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Yerwada 6297143586 Call Hot India...Call Girls in Nagpur High Profile
 
Pallawi 9167673311 Call Girls in Thane , Independent Escort Service Thane
Pallawi 9167673311  Call Girls in Thane , Independent Escort Service ThanePallawi 9167673311  Call Girls in Thane , Independent Escort Service Thane
Pallawi 9167673311 Call Girls in Thane , Independent Escort Service ThanePooja Nehwal
 
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...Pooja Nehwal
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...ranjana rawat
 
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...ranjana rawat
 
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gayasrsj9000
 
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...nagunakhan
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)kojalkojal131
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile servicerehmti665
 
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一zul5vf0pq
 
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 

Recently uploaded (20)

FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | DelhiFULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
 
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai Gaped
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai GapedCall Girls Dubai Slut Wife O525547819 Call Girls Dubai Gaped
Call Girls Dubai Slut Wife O525547819 Call Girls Dubai Gaped
 
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一
定制宾州州立大学毕业证(PSU毕业证) 成绩单留信学历认证原版一比一
 
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberCall Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
 
Book Sex Workers Available Pune Call Girls Yerwada 6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Yerwada  6297143586 Call Hot India...Book Sex Workers Available Pune Call Girls Yerwada  6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Yerwada 6297143586 Call Hot India...
 
Pallawi 9167673311 Call Girls in Thane , Independent Escort Service Thane
Pallawi 9167673311  Call Girls in Thane , Independent Escort Service ThanePallawi 9167673311  Call Girls in Thane , Independent Escort Service Thane
Pallawi 9167673311 Call Girls in Thane , Independent Escort Service Thane
 
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
 
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
 
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(PARI) Alandi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
 
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile service
 
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
 
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 

ch3_EN_BK_Process.pdf

  • 1. Silberschatz, Galvin and Gagne ©2018 Operating System Concepts Chapter 3: Processes
  • 2. 2 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Chapter 3: Processes q Process Concept q Process Scheduling q Operations on Processes q Inter-Process Communication (IPC) q IPC in Shared-Memory Systems q IPC in Message-Passing Systems q Examples of IPC Systems q Communication in Client-Server Systems
  • 3. 3 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Objectives q Identify the separate components of a process and illustrate how they are represented and scheduled in an operating system. q Describe how processes are created and terminated in an operating system, including developing programs using the appropriate system calls that perform these operations. q Describe and contrast inter-process communication using shared memory and message passing. q Design programs that uses pipes and POSIX shared memory to perform inter-process communication. q Describe client-server communication using sockets and remote procedure calls. q Design kernel modules that interact with the Linux operating system.
  • 4. 4 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Concept q An operating system executes a variety of programs that run as processes q Process – a program in execution; process execution must progress in sequential fashion q Multiple parts o The program code, also called text section o Current activity including program counter, and processor registers o Stack section containing temporary data 4 Function parameters, return addresses, local variables o Data section containing global variables o Heap section containing memory dynamically allocated during run time
  • 5. 5 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Concept (Cont.) q Program is passive entity stored on disk (e.g., executable file) q Process is active entity o Program becomes process when executable file loaded into memory q Execution of program can be started via GUI mouse clicks, command line (CLI) entry of its name, etc. q One program can be several processes o E.g., Consider multiple users executing the same program #ps -aux
  • 6. 6 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process in Memory (memory limits of a process) #size <pid>
  • 7. 7 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Memory Layout of a C Program
  • 8. 8 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process State q As a process executes, it changes state o New – The process is being created o Running – Instructions are being executed o Waiting – The process is waiting for some event to occur o Ready – The process is waiting to be assigned to a processor o Terminated – The process has finished execution
  • 9. 9 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Diagram of Process State
  • 10. 10 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Control Block (PCB) q Process Control Block (PCB) – Information associated with each process, also called Task Control Block (TCB), includes: o Process state – running, waiting, etc. o Process number – identity of the process o Program counter – location of instruction to next execute o CPU registers – contents of all process-centric registers o CPU scheduling info – priorities, scheduling queue pointers o Memory-management information – memory allocated to the process o Accounting information – CPU used, clock time elapsed since start, time limits o I/O status information – I/O devices allocated to process, list of open files
  • 11. 11 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Threads q So far, process has a single thread of execution q Consider having multiple program counters per process o Multiple locations can execute at once 4 Multiple threads of control –> threads q Must then have storage for thread details q Multiple program counters in PCB (Explore in detail in Chapter 4)
  • 12. 12 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Representation in Linux q 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 */
  • 13. 13 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Scheduling q Maximize CPU use ⇢ quickly switch processes onto CPU core q Process scheduler selects one process among available (ready) processes for next execution on CPU core q Maintains scheduling queues of processes o Ready queue – set of all processes residing in main memory, ready and waiting to execute o Wait queues – set of processes waiting for an event (e.g., I/O) q Processes migrate among the various queues
  • 14. 14 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Ready and Wait Queues
  • 15. 15 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Representation of Process Scheduling new process
  • 16. 16 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 CPU Switch from Process to Process q A context switch occurs when the CPU switches from one process to another.
  • 17. 17 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Context Switch q 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 q Context of a process represented in the PCB q Context-switch time is overhead, the system does no useful work while switching o The more complex the OS and the PCB, the longer the context switch q Time dependent on hardware support o Some hardware provides multiple sets of registers per CPU, multiple contexts loaded at once
  • 18. 18 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Multitasking in Mobile Systems q Some mobile systems (e.g., early version of iOS) allow only one process to run, others suspended q Due to screen real state, user interface limits iOS provides for a o Single foreground process – controlled via user interface o Multiple background processes – in memory, running, but not on the display, and with limits o Limits include single, short task, receiving notification of events, specific long-running tasks like audio playback q Android runs foreground and background, with fewer limits o Background process uses a service to perform tasks o Service can keep running even if background process is suspended o Service has no user interface, small memory use
  • 19. 19 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Operations on Processes q System must provide mechanisms for: o process creation o process termination
  • 20. 20 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Creation q Parent processes create children processes, which, in turn create other processes, forming a tree of processes q Process identified and managed via a Process Identifier (PID) q Resource sharing options o Parent and children share all resources o Children share subset of parent’s resources o Parent and child share no resources
  • 21. 21 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Creation (Cont.) q Execution options o Parent and children execute concurrently o Parent waits until children terminate q Address space o Child duplicate of parent o Child has a program loaded into it
  • 22. 22 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 A Tree of Processes in Linux #pstree
  • 23. 23 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Creation (Cont.) q UNIX examples o fork() system call creates new process o exec() system call used after a fork() to replace the process’ memory space with a new program o Parent process calls wait() waiting for the child to terminate
  • 24. 24 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 C Program Forking A Separate Process
  • 25. 25 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Creating a Separate Process via Windows API
  • 26. 26 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Termination q Process executes last statement and then asks the operating system to delete it using the exit() system call. o Returns status data from child to parent (via wait()) o Process’resources are deallocated by operating system q Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so: o Child has exceeded allocated resources o Task assigned to child is no longer required o The parent is exiting and the operating systems does not allow a child to continue if its parent terminates
  • 27. 27 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Process Termination (Cont.) q 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. o Cascading termination: All children, grandchildren, etc. are terminated o The termination is initiated by the operating system q 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); q If no parent waiting (did not invoke wait()), process is a zombie q If parent terminated without invoking wait(), process is an orphan
  • 28. 28 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Importance Hierarchy of Android Process q Mobile operating systems often have to terminate processes to reclaim system resources such as memory. From most to least important: ▲ Foreground process ▲ Visible process ▲ Service process ▲ Background process ▲ Empty process q Android will begin terminating processes that are least important.
  • 29. 29 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Multiprocess Architecture – Chrome Browser q Many web browsers ran as a single process (some still do) o If one web site causes trouble, entire browser can hang or crash q Google Chrome Browser is multiprocess with 3 different types of processes: o Browser process manages user interface, disk and network I/O o Renderer process renders web pages, deals with HTML, JavaScript. A new renderer created for each website opened 4 Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits o Plug-in process for each type of plug-in
  • 30. 30 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Inter-Process Communication (IPC) q Processes within a system may be independent or cooperating o Independent process does not share data with any other processes executing in the system o Cooperating process can affect or be affected by other processes, including sharing data q Reasons for cooperating processes: o Information sharing o Computation speed-up o Modularity o Convenience q Cooperating processes need Inter-Process communication (IPC)
  • 31. 31 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Communication Models q Two models of IPC o Shared memory o Message passing Shared memory Message passing
  • 32. 32 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Inter-Process Communication – Shared Memory q An area of memory shared among the processes that wish to communicate q The communication is under the control of the users processes, not the operating system. q 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)
  • 33. 33 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Producer-Consumer Problem q Producer-Consumer relationship q Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process o unbounded-buffer places no practical limit on the size of the buffer o bounded-buffer assumes that there is a fixed buffer size
  • 34. 34 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Bounded-Buffer – Shared-Memory Solution q Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; q Solution is correct, but can only use BUFFER_SIZE-1 elements
  • 35. 35 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 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; }
  • 36. 36 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 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 */ }
  • 37. 37 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Inter-Process Communication – Message Passing q Mechanism for processes to communicate and to synchronize their actions q Message system – processes communicate with each other without resorting to shared variables q IPC facility provides two operations: o send(message) o receive(message) q The message size is either fixed or variable
  • 38. 38 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Message Passing (Cont.) q If processes P and Q wish to communicate, they need to: o Establish a communication link between them o Exchange messages via send/receive q Implementation issues: o How are links established? o Can a link be associated with more than two processes? o How many links can there be between every pair of communicating processes? o What is the capacity of a link? o Is the size of a message that the link can accommodate fixed or variable? o Is a link unidirectional or bi-directional?
  • 39. 39 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Message Passing (Cont.) q Implementation of communication link o Physical 4 Shared memory 4 Hardware bus 4 Network equipment o Logical 4 Direct or indirect 4 Synchronous or asynchronous 4 Automatic or explicit buffering 4 Network protocols
  • 40. 40 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Direct Communication q Processes must name each other explicitly: o send (P, message) – send a message to process P o receive(Q, message) – receive a message from process Q q Properties of communication link o Links are established automatically o A link is associated with exactly one pair of communicating processes o Between each pair there exists exactly one link o The link may be unidirectional, but is usually bi-directional
  • 41. 41 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Indirect Communication q Messages are directed and received from mailboxes (also referred to as ports) o Each mailbox has a unique ID o Processes can communicate only if they share a mailbox q Properties of communication link o Link established only if processes share a common mailbox o A link may be associated with many processes o Each pair of processes may share several communication links o Link may be unidirectional or bi-directional
  • 42. 42 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Indirect Communication (Cont.) q Operations o create a new mailbox (or port) o send and receive messages through mailbox o destroy a mailbox q Primitives are defined as: o send(A, message) – send a message to mailbox A o receive(A, message) – receive a message from mailbox A
  • 43. 43 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Indirect Communication (Cont.) q Mailbox sharing o Example 4 P1, P2, and P3 share mailbox A, 4 P1 sends; P2 and P3 receive. 4 Who gets the message? o Solutions 4 Allow a link to be associated with at most two processes 4 Allow only one process at a time to execute a receive operation 4 Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was
  • 44. 44 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Message Passing – Synchronization q Message passing may be either blocking or non-blocking q Blocking is considered synchronous o Blocking send – the sender is blocked until the message is received o Blocking receive – the receiver is blocked until a message is available q Non-blocking is considered asynchronous o Non-blocking send – the sender sends the message and continue o Non-blocking receive – the receiver receives: 4 A valid message, or Null message q Different combinations possible o If both send and receive are blocking, we have a rendezvous
  • 45. 45 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Producer – Message Passing message next_produced; while (true) { /* produce an item in next_produced */ send(next_produced); }
  • 46. 46 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Consumer – Message Passing message next_consumed; while (true) { receive(next_consumed) /* consume the item in next_consumed */ }
  • 47. 47 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Buffering q Queue of messages attached to the link. q Implemented in one of three ways o Zero capacity – no messages are queued on a link 4 Sender must wait for receiver (rendezvous) o Bounded capacity – finite length of n messages 4 Sender must wait if link full o Unbounded capacity – infinite length 4 Sender never waits
  • 48. 48 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Examples of IPC Systems - POSIX q POSIX Shared Memory o Process first creates shared memory segment shm_fd = shm_open(name, O CREAT | O RDWR, 0666); o Also used to open an existing segment o Set the size of the object ftruncate(shm_fd, 4096); o Use mmap() to memory-map a file pointer to the shared memory object o Reading and writing to shared memory is done by using the pointer returned by mmap().
  • 49. 49 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 IPC POSIX Producer – Consumer
  • 50. 50 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Examples of IPC Systems - Mach q Mach communication is message based o Even system calls are messages o Each task gets two ports at creation – Task Self port and Notify port o Messages are sent and received using the mach_msg() function o Ports needed for communication, created via mach_port_allocate() o Send and receive are flexible, for example four options if mailbox full: 4 Wait indefinitely 4 Wait at most n milliseconds 4 Return immediately 4 Temporarily cache a message
  • 51. 51 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Mach Messages #include<mach/mach.h> struct message { mach_msg_header_t header; int data; }; mach port t client; mach port t server;
  • 52. 52 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Mach Message Passing - Client
  • 53. 53 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Mach Message Passing - Server
  • 54. 54 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Examples of IPC Systems – Windows q Message-passing centric via advanced Local Procedure Call (LPC) facility o Only works between processes on the same system o Uses ports (like mailboxes) to establish and maintain communication channels o Communication works as follows: 4 The client opens a handle to the subsystem’s connection port object 4 The client sends a connection request 4 The server creates two private communication ports and returns the handle to one of them to the client 4 The client and server use the corresponding port handle to send messages or callbacks and to listen for replies
  • 55. 55 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Local Procedure Calls in Windows
  • 56. 56 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Pipes q Acts as a conduit allowing two processes to communicate q Issues: o Is communication unidirectional or bidirectional? o In the case of two-way communication, is it half or full-duplex? o Must there exist a relationship (e.g., parent-child) between the communicating processes? o Can the pipes be used over a network? q Ordinary pipes – cannot be accessed from outside the process that created it. Typically, a parent process creates a pipe and uses it to communicate with a child process that it created. q Named pipes – can be accessed without a parent-child relationship.
  • 57. 57 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Ordinary Pipes q Ordinary Pipes allow communication in standard producer-consumer style o Producer writes to one end (the write-end of the pipe) o Consumer reads from the other end (the read-end of the pipe) q Ordinary pipes are therefore unidirectional q Require parent-child relationship between communicating processes
  • 58. 58 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Named Pipes q Named pipes are more powerful than ordinary pipes q Communication is bidirectional q No parent-child relationship is necessary between the communicating processes q Several processes can use the named pipe for communication q Provided on both UNIX and Windows systems
  • 59. 59 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Communications in Client-Server Systems q Sockets o A socket is defined as an endpoint for communication o It is a concatenation of IP address and port – a number included at start of message packet to differentiate network services on a host 4 E.g., The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 o Communication consists between a pair of sockets o All ports below 1024 are well known, used for standard services o Special IP address 127.0.0.1 (loopback) to refer to system on which process is running q Remote Procedure Calls (RPC)
  • 60. 60 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Socket Communication
  • 61. 61 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Sockets in Java – Server q Three types of sockets o Connection-oriented (TCP) o Connectionless (UDP) o MulticastSocket class– data can be sent to multiple recipients q Consider this “Date” server in Java:
  • 62. 62 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Sockets in Java – Client q The equivalent “Date” client
  • 63. 63 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Remote Procedure Calls q Remote Procedure Call (RPC) abstracts procedure calls between processes on networked systems o Again uses ports for service differentiation q Stubs – proxies for the actual procedure on the server and client sides o The client-side stub locates the server and marshals the parameters o The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server q On Windows, stub code compile from specification written in Microsoft Interface Definition Language (MIDL)
  • 64. 64 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Remote Procedure Calls (Cont.) q Data representation handled via External Data Representation (XDR) format to account for different architectures o E.g., Big-endian (Motorola) and little-endian (Intel x86) q Remote communication has more failure scenarios than local o Messages can be delivered exactly once rather than at most once q OS typically provides a rendezvous (or matchmaker) service to connect client and server
  • 65. 65 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Execution of RPC
  • 66. 66 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Summary q A process is a program in execution, and the status of the current activity of a process is represented by the program counter, as well as other registers. q The layout of a process in memory is represented by four different sections: (1) text, (2) data, (3) heap, and (4) stack. q As a process executes, it changes state. There are four general states of a process: (1) ready, (2) running, (3) waiting, and (4) terminated. q A process control block (PCB) is the kernel data structure that represents a process in an operating system. q The role of the process scheduler is to select an available process to run on a CPU.
  • 67. 67 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Summary (Cont.) q An operating system performs a context switch when it switches from running one process to running another. q The fork() and CreateProcess() system calls are used to create processes on UNIX and Windows systems, respectively. q When shared memory is used for communication between processes, two (or more) processes share the same region of memory. POSIX provides an API for shared memory. q Two processes may communicate by exchanging messages with one another using message passing. The Mach operating system uses message passing as its primary form of inter-process communication. Windows provides a form of message passing as well.
  • 68. 68 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Summary (Cont.) q A pipe provides a conduit for two processes to communicate. There are two forms of pipes, ordinary and named. Ordinary pipes are designed for communication between processes that have a parent- child relationship. Named pipes are more general and allow several processes to communicate. q UNIX systems provide ordinary pipes through the pipe() system call. Ordinary pipes have a read end and a write end. A parent process can, for example, send data to the pipe using its write end, and the child process can read it from its read end. Named pipes in UNIX are termed FIFOs.
  • 69. 69 Operating System Concepts Silberschatz, Galvin and Gagne ©2018 Summary (Cont.) q Windows systems also provide two forms of pipes—anonymous and named pipes. Anonymous pipes are similar to UNIX ordinary pipes. They are unidirectional and employ parent-child relationships between the communicating processes. Named pipes offer a richer form of inter-process communication than the UNIX counterpart, FIFOs. q Two common forms of client-server communication are sockets and remote procedure calls (RPCs). Sockets allow two processes on different machines to communicate over a network. RPCs abstract the concept of function (procedure) calls in such a way that a function can be invoked on another process that may reside on a separate computer. q The Android operating system uses RPCs as a form of inter-process communication using its binder framework.
  • 70. Silberschatz, Galvin and Gagne ©2018 Operating System Concepts End of Chapter 3