Download OperatingSystems_FA15_3_Process

Document related concepts

Unix security wikipedia , lookup

Distributed operating system wikipedia , lookup

Burroughs MCP wikipedia , lookup

DNIX wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
Operating Systems
Dr. Jerry Shiao, Silicon Valley University
Fall 2015
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
1
Processes
 Overview

Process Concepts


Process is Program in Execution
Process Control Blocks ( PCB )



Process State and State Transition
Queuing Model
Operating System Responsibilities:




Process Scheduling
 Short-Term, Long-Term, Medium-Term Schedulers
Operations on Process
 Process Creation / Termination / Suspension
 Process Mode Change / Process State Change
InterProcess Communication
 Shared-Memory Systems
 Message-Passing Systems
Communication in Client-Server Systems
 Sockets
 Remote Procedure Calls
 Pipes
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
2
Processes
 Fundamental Task of Operating System:


Operating System must:






Allocate Resources to Processes.
Protect Resources of Process from other Processes.
Execute System Tasks outside of the Kernel (i.e. sshd Daemon,
inetd Daemon).
Support InterProcess Communication and User Creation of
Processes.
Interleave execution of User Processes and System Processes
to maximize CPU.
Operating System maintains a Data Structure for each
Process.


Process Management.
Enables Operating System to exert Process Control.
Difficulty of Process Management: Concept of Thread.

Thread Property allows concurrent execution streams running
within a Process.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
3
Processes
 Process Concept
 Process is a unit of work in a Time-Sharing System.
 Process in Memory contains:






Text Section – Program code.
CPU Program Counter
CPU Registers
Stack – Temporary data ( function parameters, return addresses,
local variables ).
Data Section – Global variables.
Heap – Dynamically allocated memory during execution.
Max
Stack
Process in Memory
Heap
Data
0
Copyright @ 2009 John
Wiley & Sons Inc.
Text
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
4
Processes


Process Concept
Process Control Block ( PCB )

Process State:


Program Counter:


Base and limit registers, page tables.
Accounting Information:


Process priority, pointer to scheduling queues.
Memory-Management Information:


Accumulators, index registers, stack pointers, general purpose.
CPU-Scheduling Information:


Address of instruction to be executed.
CPU Registers:


New/Ready/Running/Waiting/Terminated
Amount of CPU time used, accounting numbers.
I/O Status Information:

List of I/O devices allocated to the process, list of open files.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
5
Processes

Process Control Block ( PCB )



Process consists of Program Code, associated Data, and PCB.
Executing Program is characterized by PCB Data Structure.
PCB allows Operating System to interrupt a running process,
support multiple processes, and multiprocessing. Process Control Block
Unique Identifier associated with process.
Running, Ready, Blocked/Waiting, New, Exit
Priority level relative to other processes.
Address of next instruction in program.
Pointer to program code, process data,
shared memory blocks.
Data in Registers in the processor.
Outstanding I/O Requests, I/O Devices
assigned to process, List of files used by
process.
Processor time and clock time used, time
limits, account numbers, statistics.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
6
Processes
 Process Concept

Processor View:

Example: Memory Layout three processes.
Dispatcher or Scheduler
(Runs same code).
Program Counter Instruction Trace
Interleaved Traces of Instructions.
Process A
Process A
Process B
Process C
Process C
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
7
Processes

Process Concept

Processor View:

Time Line
Process Running.
Round Robin Scheduling.
Scheduler Running.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
8
Processes



Process Concept
Operating System determines interleaving pattern for execution and
allocating resources to process.
Two-State Process Model
Simple Process State, either Running
or Not Running.
Operating System keeps track of PCB
in a queue.
Queue entry is a pointer to the PCB.
Inefficent, need to search every entry
in Queue to find non-blocked process
to run.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
9
Processes


Process Concept
Five-State Model

Ready State needs additional state for process waiting (blocked)
for event ( I/O ).



Queue for Blocked Processes waiting for an Event
Require: Queue for each Event.
Ready State processes are dispatched based on Priority
Scheme.

Require: Queue for each Priority Level.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
10
Processes
 Process Concept
 Process State Transition

Null  New:


New  Ready:


Process notifies OS to exits or abort. Process tables and other information
temporarily preserved until OS utilities extract the needed information.
Running  Ready:


OS Scheduler selects one of the processes in the Ready state to run.
Running  Exit:


OS ready schedule the new process.
Ready  Running:


New User logs in or new Batch Job is submitted. PCB with Process ID is
created, but OS has not brought the job into memory. Example: OS has limit
of number of processes (prevent performance degradation) or memory not
available.
Process has reached its quantum and OS uses scheduling algorithm to find
next process in the Ready state. OS will preempt running Process, when a
higher priority process is ready to run. Process can also voluntarily release
processor.
Running  Blocked:

Process issues a request and must wait for the event. Process makes a
System Call (I/O Operation,
blocking for a semaphore).
SILICON VALLEY UNIVERSITY
Copyright @ 2009 Pearson
Education, Inc.
CONFIDENTIAL
11
Processes
 Process Concept
 Process State Transition

Blocked  Ready:


Ready  Exit:


Event for which a process is waiting for has occurred.
Parent process terminates a child process. Parent process terminates and
all child processes also terminates.
Blocked  Exit:

Parent process terminates a child process. Parent process terminates and
all child processes also terminates.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
12
Processes


Process Concept
Queuing Model
Ready Queue could
be expanded to
queue per Priority.
Event Queue:
Queue per Event.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
13
Processes


Process Concept
Process Creation


Operating System builds Process Control Block to manage the
Process.
Actions that will create a new Process:
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
14
Processes
 Process Concept
 Process Termination
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
15
Processes
 Process Concept
 Reasons for Process Suspension:
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
16
Processes
 Process Concept
 Swapping



Larger memory means larger processes, not more processes in
memory.
Moving part or all of a process from Main Memory to Disk.
Characteristics of a Swapped or Suspended State for a
Process:



Process not immediately available for execution.
Process may or may not be waiting on an event. Blocking
condition is independent of the suspend condition: just that the
process will not be executing in the near future.
Process placed in Suspend State by an agent: itself, parent
process, or the Operating System to prevent its execution.

Agent must explicitly remove the process from the Suspend State.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
17
Processes
 Process Concept
 Swapping
 Process States Affected:

Running:


Ready:


Process in Main Memory and available for execution.
Blocked:


Process currently executing on processor.
Process in Main Memory and waiting for an event ( I/O, semaphore ).
Process Swapped State Added:

Blocked/Suspend:


Blocked Process swapped-out and waiting for an event.
Ready/Suspend:

Event occurs for a swapped-out process (Block/Suspend State) or Process
(Ready State) must be swapped-out to free Main Memory for higher priority
Process to run.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
18
Processes
 Process Concept
 Swapping
Choices for selecting
process to bring back to
Main Memory:
1) Newly created process
directly admitted to Main
Memory or transitioned to
Ready State.
2) Previously suspended
process that has
transitioned to Ready
State.
3) Previously suspended
process still in the Blocked
State.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
19
Processes
 Process Concept
 Process State Transition

Blocked  Blocked/Suspend:


Blocked/Suspend  Ready/Suspend:


OS needs to free up Main Memory for current process or next scheduled
process.
New  Ready/Suspend:


OS Schedular already scheduled other Ready processes or process has
higher priority than other Ready processes.
Ready  Ready/Suspend:


Event waited on by the Blocked process occurs.
Ready/Suspend  Ready:


Current process or Ready or Ready/Suspend process needs Main Memory,
newly created process needs Main Memory.
New process cannot be added into Main Memory.
New  Ready:

New process can be added into Main Memory.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
20
Processes
 Process Concept
 Process State Transition

Blocked/Suspend  Blocked:


Running  Ready/Suspend:


Preemptive move when Main memory is available, and Blocked/Suspend
State process has high priority.
OS preempting current process when higher-priority Ready/Suspend or
Blocked/Suspend process has become unblocked and ready for execution.
Any State  Exit

Process completes execution or fatal fault condition occurs. Process can be
terminated by process that created it or the parent process itself is
terminated.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
21
Processes
 Process Description
 Operating System must manage the System Resources
for Processes.
 What Information is needed by Operating System to
control Processes and Manage Resources?
 Operating System Control Structures:

Memory Tables: Information Required







Allocation of Main Memory (blocks) to Processes (Process ID).
Allocation of Secondary Memory to Processes.
Any protection attributes of blocks of Main or Virtual Memory (shared
memory regions).
Information needed to manage Virtual Memory.
I/O Tables: Used to manage the I/O Device and monitor the
status of the I/O operations.
File Tables: File Management System manages the mapping of
files (Directories) to Secondary Memory.
Process Tables: List of Process Control Blocks (PCBs) used to
manage processes.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
22
Processes
 Process Description
 Operating System Control Tables
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
23
Processes
 Process Concept
 Process Creation:


New User logs in or new Batch Job is submitted.
Create new entry in the Process Table.


Allocate space for the process.




Process State Information initialized. Process State is Ready or
Ready/Suspended.
Process Control Information initialized. Process Priority set to default (lowest
priority) or user request.
Set linkages.


Operating System allocates private User address space (programs and data)
and User Stack.
Assigned as default or user request at process creation time.
Initialize the Process Control Block.


Assign a unique process identifier to the entry.
Place PCB into Ready or Ready/Suspended linked list.
Create or expand other Data Structures.

Operating System may maintain an accounting file on each process to be
used for billing.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
24
Processes
 Process Concept
 Process Switching



Running Process is interrupted and the Operating System
assigns another process to the running state and the process
takes control over the processor.
May occur when Operating System gains control from currently
running process.
Mechanisms for Interrupting the Execution of a Process.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
25
Processes
 Process Concept
 Process Switching: System Interrupts
 Interrupts:

Clock Interrupt: Operating System determines currently running process
has exceeded its allowable running time (Quantum). Currently running
process


I/O Interrupt: Operating System determines I/O action completed.


All blocked processes waiting for this I/O event has their Process State from
Blocked or Blocked/Suspend to Ready or Ready/Suspend.
Memory Fault: Process Virtual Memory reference for addresses not in
Main Memory.


Process State switched to Ready or Ready/Suspended and another process
scheduled.
Process switched to Blocked and OS switch to another process.
Traps

Fatal error or exception condition.


Process State changed to Exit and OS switch to another process.
System Call.

Operating System service can place the Process in a Blocked state ( I/O
Request ).
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
26
Processes
 Process Concept
 Process State Change
 Operating System Environment Changes







Processor context ( Program Counter and other Process State
Information) saved in PCB. Update other PCB Process Control
Information fields.
Process State changed to other state (Ready, Blocked, …).
PCB moved to appropriate queue (Ready, Blocked on Event, …).
Select another process for execution (Highest priority).
Selected process Process State changed to Running.
Update Process Memory Management data structures (Page
Table).
Restore context of selected process. Program Counter restored
to the instruction to be executed before the process was
switched out.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
27
Processes
 Process Concept
 Mode Switching



Different than Process State Change (Context Switch).
Switch from User Mode to Kernel Mode to execute Kernel code.
Interrupt Detection:


Instruction cycle, processor checks for presence of interrupt
signal after executing the instruction.
If an interrupt is pending:




Sets Program Counter to Interrupt Handler program.
Switches from User Mode to Kernel Mode so that privileged instructions can
be executed.
Context of the interrupted user process (the processor state information:
Program Counter, registers, stack information) is saved in the Process
Control Block of the interrupted program.
After interrupt completes:


If another process is scheduled (interrupt is the Real-Time Clock and the
current process running time has expired), then a Process State change
occurs.
If the current running process can resume execution, then the processor
state information is restored from the PCB and the process resumes running.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
28
Processes
 Process Concept
 Operating System Design Approaches
 Execution within User Process:
Process Image
When interrupt, trap, or System Call occurs, the
processor is placed in Kernel Mode and the
user mode context is saved and a mode switch
takes place to an OS routine.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
29
Processes
 Process Concept
 Operating System Design Approaches
 Process-Based Operating System



Operating System as a collection of system processes: Major Kernel
functions are organized as separate processes.
Modular Operating System design.
In multiprocessor environment, OS services can execute on dedicated
processors.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
30
Processes
 Process Concept
 UNIX System V




Operating System executes within the environment of User
Process (System Calls, Interrupts, Traps).
System Processes: Run in Kernel Mode for OS administrative
and management functions (allocation of memory, swapping).
User Processes: Run in User Mode for User programs and
utilities and Kernel Mode when System Call, Trap, or Interrupt
occurs.
Nine Process States with following new states:


Two Running States, indicates whether process is in User Mode
or Kernel Mode.
Two Ready States, Ready to Run/In Memory and Preempted.
Preempted State occurs when process is in Kernel Mode from
System Call, Clock Interrupt, or I/O Interrupt, and the current
Process must be preempted to allow a higher priority process in
Ready state to run.
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
31
Processes
 Process Concept
 UNIX System V Process Management
 UNIX Process States
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
32
Processes
 Process Concept
 UNIX System V Process Management
 UNIX Process State Transition Diagram
Copyright @ 2009 Pearson
Education, Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
33
Processes


Operations on Processes
Windows Process Creation


Windows: CreateProcess ( ) System Call.
 Similar to UNIX fork( ), but CreateProcess( ) is passed, as a
parameter, the program to load and execute.
Process Termination

Child exceeded resource usage ( shared
with parent and other child processes ).
 Child’s program execution not needed.
 Parent termination.
WaitForSingleObject( )
Parent
CreateProcess ( )
Parent
Resumes
Child
‘cmd’
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
exit( )
34
Processes


Operations on Processes
UNIX Process Creation



Process ( parent process ) creates new processes ( child
process ).
Process Identifier ( PID ) uniquely identifies a process.
UNIX: fork ( ) System Call.


Created process used to execute another program in parallel ( parent
process continue to execute ) or parent program will wait for child process to
complete.
exec ( ) system call loads binary image into memory to execute, but loaded
over the process that called exec ( ).
Parent
fork( )
wait( )
Parent
Resumes
Child
exec(‘cmd’ )
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
exit( )
35
Processes
 Process Concept
 Threads


Executing
Process performs single thread of execution.
Multiple threads per process used for Multi-programming.
Process P0
Operating System
Process P1
Interrupt or System Call
Save State into PCB0
...
Reload State From PCB1
Executing
Interrupt or System Call
Save State into PCB1
...
Executing
Copyright @ 2009 John
Wiley & Sons Inc.
Reload State From PCB0
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
36
Processes
 Process Scheduling

Objectives:



Ready Queue:


Processes waiting to execute.
Device Queues:


For Multi-Programming, maximize CPU utilization.
For Time Sharing, switch CPU amount processes
Processes waiting for I/O Request to complete.
Scheduling Queues
PCB 0
Ready Queue
Disk Unit 0
PCB 2
Head
Head
Head
Tail
Registers
Registers
...
...
NULL
PCB 3
Head
Head
Tail
Registers
NULL
...
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
37
Processes
 Process Scheduling
 Schedulers

Short-Term Scheduler





Selects a new process for the CPU frequently ( every 100 milliseconds ).
I/O bound processes - Interactive processes are I/O-bound, spending a lot of
time waiting for I/O operations.
Interactive processes waiting for human input.
 Response time must be quick (latency 50-150ms).
 Command shells, text editors, graphical applications, mouse and
keyboard processes.
Time-Sharing systems, UNIX and Microsoft Windows.
Long-Term Scheduler




Selects a new process less frequently ( order of minutes ).
Controls the degree of multi-programming ( number of processes in
memory ). Ideally, new process starts as a process exits.
CPU bound processe - Batch processes are CPU-bound, heavily ultilize
CPU time for computations.
 Batch processes typically executing in background, i.e. compilers,
database search engines, and scientific computiations.
 No user interactions.
Batch systems, IBM mainframe systems.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
38
Processes


Process Scheduling
Schedulers

Medium-Term Scheduler




Time-Sharing systems needs combination of short and long term schedulers.
Reduce the degree of mult-programming ( remove processes from memory )
and contention for CPU by swapping processes out to disk.
Overcommitted available memory.
Process swapped in later when process mix is more favorable.
Swap In
Process To Be
Scheduled
Partially Executed
Swapped-Out Processes
Process
Terminate
Scheduled
Ready Queue
I/O
Copyright @ 2009 John
Wiley & Sons Inc.
Swap Out
CPU
I/O Waiting Queues
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
39
Processes


Process Scheduling
Context Switch

Interrupts switch CPU from executing process to Kernel process.


PCB contains context of the process





Need to save and restore interrupted process.
CPU Registers
Process State
Memory-Management Information
Switch the CPU to another process
All Overhead, speed depends on:



Memory Speed
Number of registers
Hardware assist



Copyright @ 2009 John
Wiley & Sons Inc.
Single instruction to load or restore all registers .
CPU contains multiple sets of registers ( Sun UltraSPARC ).
Preserve and restore process Page Table.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
40
Processes



Interprocess Communication
Process is independent if it cannot affect or be affected
by other processes in the system.
Process is cooperating if it can affect or be affected by
other processes in the system.





Concurrent access to shared data.
Computational speedup with subtasks.
Modularity in system design with separate processes or threads.
Convenience with subtasks.
Cooperating Process and InterProcess Communcation
( IPC )

Shared-Memory Systems


Region of memory shared between processes to exchange
messages and data.
Message Passing Systems

Messages exchanged through System Calls to the Kernel.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
41
Processes

Interprocess Communication
Message Passing
Process A
Shared memory
M
Process A
Shared
Process B
M
Kernel
M
Copyright @ 2009 John
Wiley & Sons Inc.
Process B
Kernel
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
42
Processes


Interprocess Communication
Shared-Memory Systems



Shared Region exists in the address space of the process
creating the shared-memory segment.
Processes must handle synchronizing shared-memory segment
read and write.
Cooperating Processes: Producer – Consumer

Producer ( Server ): Produces information


Consumer ( Client ): Consumes information


Web Server creates and sends HTML files and images.
Web Browser reads the HTML files and images.
Producer – Consumer relationship between local processes
represented by shared-memory segment.



Shared-memory segment circular buffer and in / out pointers.
Producer process writes into circular buffer moving in pointer.
Consumer process reads from circular buffer moving out pointer.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
43
Processes




Interprocess Communication
Shared-Memory Systems
POSIX API for Shared Memory
Create shared-memory segment
segment_id = shmget( segment_id, size, S_IRUSR | S_IWUSR )
segment_id = IPC_PRIVATE or ftok(“<filename>”, id)
IPC_PRIVATE: New shared memory segment is created.
size: In bytes of shared-memory segment.
S_IRUSR | S_IWUSR: Read and write to shared-memory segment.

Access shared-memory segment
shared_memory = (char *) shmat( segment_id, NULL, 0 )
shared_memory: Pointer to shared-memory segment.
segment_id: Shared-memory segment identifier.
NULL: Operating System selects where to attach the shared-memory.
0: Attach shared-memory in read / write mode.

Remove shared-memory segment
shmdt ( shared_memory )
shared memory: Detach shared-memory region.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
44
Processes
 Interprocess Communication
 Message-Passing System
 Operating System provides message-passing facility for
cooperating processes.
 Communication Link for send ( ) / receive ( ) operations:


How to refer to the process
Direct Communication




Explicitly name the recipient or sender establishes link automatically:
 send ( <processID1>, message ), receive ( <processID2>, message ).
Symmetry addressing ( recipient and sender names must be known).
Asymmetry addressing ( Sender name known, recipient receives processID ).
 send ( <processID1>, message ), receive ( <id>, message ).
Indirect Communication




Messages sent to and received from mailboxes or ports (unique identifier).
 send ( <mailbox ID>, message ), receive ( <mailboxID>, message )
Process has number of different links, each link corresponding to one
mailbox.
Mailbox Process Owned: Dependency, unique owner.
Mailbox Operating System Owned: Independent, not attached to a process.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
45
Processes
 Interprocess Communication
 Message-Passing System
 Communication Link for send ( ) / receive ( ) operations:

Synchronous Communications



Asynchronous Communications



Blocking Send: Sending process blocked until receive by process or mailbox.
Blocking Receive: Receiving process blocks until message received.
NonBlocking Send: Sending process not blocked.
NonBlocking Receive: Receiving process receives message or NULL.
Buffering




Messages exchanged reside in queue.
Zero Capacity: Queue has depth of zero. Sender must block until
the recipient receives the message.
Bounded Capacity: Queue has n depth. Sender must block when
the queue is full.
Unbounded Capacity: Queue has infinite depth. Sender never
blocks.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
46
Processes
 Interprocess Communication
 Message-Passing System: Mach Operating System
(MicroKernel)
 System Calls and all intertask communication handled
by messages (ports).

Application Created: Kernel Mailbox and Notify Mailbox are
created.







Kernel Mailbox: Communication between Kernel and the task.
Notify Mailbox: Kernel sends notification of events to the task.
port_allocate ( ) System Call creates new mailbox and allocate space for 8
(default) messages.
All messages has same priority, FIFO ordering.
Messages contents has list of typed data items (Type:Length:Value).
Mailbox Set (Server Tasks): Collection of mailboxes treated as one mailbox.
Intrasystem Messaging:


Virtual Memory Management to eliminate physical message copying.
Mach maps Sender address space containing Sender’s Message into the
Receiver address space.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
47
Processes


Interprocess Communication
Message-Passing System: Windows XP

Local Procedure Calls (LPC) communicates between two processes.
 Win32 API Remote Procedure Calls (RPC) indirectly handle messages on
the same Computer System as LPC.
 Two Connection Port Objects:
 Connection Port visible to all processes.
 Communication Port between client and server.
Client
Application
Programs
Server
Connection
Request
Connection Port
Handle
Handle
Client Communication
Port (Small Messages)
Server Communication
Port (Small Messages)
Handle
Windows XP
Subsystem Server
Communication Port:
Copies messages
between Client and
Server.
Section Object Port:
Uses shared memory
Shared Section
Object
(<= 256 Bytes)
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
48
Processes


Client-Server System Communications
Sockets


Endpoints for communication.
Network IP address: port uniquely identifies connection




Port identifies the services to handle the request.
Port 23 = Telnet, Port 21 = FTP, Port 80 = HTTP.
Ports below 1024 are well-known for standard services.
Structure of message imposed by the client and server.
Client: Web Browser
Server: Web Server
Dest=192.168.1.100 : 80
Src = 192.168.1.10 : 1625
Dest = 192.168.1.10 : 1625
Src = 192.168.1.100 : 80
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
49
Processes
 Client-Server System Communications
 Remote Procedure Calls ( RPC )



Abstract procedure-call mechanism to use between computer
systems over a network connection.
Network IP address: RPC port uniquely identifies RPC program
RPC Port:


Statically defined RPC port number.
A daemon (program) at fixed port number that returns the RPC port number.
Client: Send command in RPC message.
Server: Process command in RPC message.
Dest=192.168.1.100 : <RPC port>
Src = 192.168.1.10 : 1625
Dest = 192.168.1.10 : 1625
Src = 192.168.1.100 : <RPC port>
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
50
Processes
 Client-Server System Communications
Client
Message
Server
User calls Kernel to
send RPC message
to procedure X.
Kernel sends
message to MM to
find port number.
From: Client
To: Server, Port: MM
Re: Address for RPC X
MM (MatchMaker)
receives message,
looks up answer.
Kernel places port P
in user RPC
message.
From: Server
To: Client, Port: Kernel
Re: RPC X Port: P
Matchmaker replies
to client with port P.
Kernel sends RPC.
From: Client
To: Server, Port: P
< contents >
Daemon listening to
port P receives
message.
Kernel receives
reply, passes it to
user.
From: RPC, Port: P
To: Client, Port: Kernel
< output >
Daemon processes
request and process
send output.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
51
Processes
 Client-Server System Communications
 Pipes
 Conduit allowing two processes to communicate
 Ordinary Pipes




Unidirectional, one-way communication.
Two-way communication require two pipes.
Parent-Child process relationship.
UNIX treats pipes as special files, requiring file descriptors.




pipe ( int fd [ ] ) command creates two file descriptors.
fd [ 0 ] is the read-end of the pipe.
fd [ 1 ] is the write-end of the pipe.
Use standard read ( ) and write ( ) system calls.
Parent
fd(0)
Child
fd(1)
fd(0)
fd(1)
Pipe
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
52
Processes
 Client-Server System Communications
 Pipes
 Named Pipes




Bidirectional, but only half-duplex is permitted.
No Parent-Child process relationship.
Named pipes continue to exist after processes exits.
UNIX treats pipes as special FIFO files, requiring file descriptors.





mkfifo ( char *pathname ) command creates file.
Use standard open ( ) to get file descriptor and then use read ( ) and
write ( ) system calls.
Both sides of fifo file must be opened, else one side blocks on open
until another process opens the fifo file.
Processes must reside on same computer system.
Windows bidirectional, full-duplex permitted.




Processes can reside on the same or different computer systems.
CreateNamedPipe ( ) creates the named pipe.
ConnectNamedPipe ( ) connects to named pipe.
ReadFile() and WriteFile() used to manipulate the named pipe.
Copyright @ 2009 John
Wiley & Sons Inc.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
53
Processes
 Summary
 Process is a Unit of Work in the Operating System.
 System and User Processes Execute Concurrently with
Operating System Multiplexing CPU Between Processes.
 Operating System Placed Processes in Queues.
 Two major classes of queues: I/O Request Queue and
Ready Queue.
 Scheduling the Queues:


Parent / Child Process


Executes Concurrent or Parent Waits for Child Terminate.
Inter-Process Communication


Long-Term Scheduler, Short-Term Scheduler, Medium-Term
Scheduler.
Shared Memory and Message Passing
Client-Server Systems
Sockets, Remote Procedure Calls (RPC), Pipes (Ordinary and
Named)
SILICON VALLEY UNIVERSITY
Copyright @ 2009 John

Wiley & Sons Inc.
CONFIDENTIAL
54