Transcript Processes

Processes
CSCI 4534
Chapter 4
Introduction
• Early computer systems allowed one
program to be executed at a time
– The program had complete control of the
computer
– The program had access to all system resources
• Current computer systems allow multiple
programs:
– To be loaded into memory
– To be executed “concurrently”
Introduction
• What do these terms mean:
– program in execution?
– unit of work in a time-sharing environment?
• Do not use either of these terms unless you
can more clearly embellish and define them.
Introduction
• Main concerns of an operating system:
– To execute user programs
– To execute system programs
Process States
•
•
•
•
•
New
Ready
Running
Waiting
Terminated
Process Control Blocks
• Each process is represented in the O.S. by a PCB
–
–
–
–
Process State
Program Counter
CPU Register contents
Information about:
• scheduling priority and queues
• memory limit and base registers, page tables
• accounting of CPU time used, time limits, acct #s
• I/O status of resources allocated and available
Process Scheduling
• Scheduling Queues
– Ready Queue is a linked list
• A header may have pointers to head and tail
• PCBs are linked together as in Figure 4.4
– I/O device queues
• Queueing Diagrams
– See Figure 4.5
Process Scheduling
• Schedulers
– Long-term: to load into memory
• Determines degree of multiprogramming
• Mix of CPU-bound and I/O-bound processes
– Short-term: allocates CPU to a process
• How much overhead do schedulers
contribute?
– Context switching
Process Scheduling
• Adding a medium-term scheduler
– To reduce the degree of
multiprogramming
– To keep down contention for CPU
– Remove process(es) from memory and
swap them back in later
Context Switching
• CPU is switched to a different process
– save state of current process
– load saved state of another process
• as in Figure 4.3
• this time is pure overhead; no useful work
gets done
• speed ranges from 1 to 1000 microseconds
Context Switching
• Hardware support for context
switching
– Processors may provide multiple sets of
registers; change a pointer to current set
– Or register data is copied between
registers and memory
• Threads are used to avoid performance
problems of context switching
Process Creation
• New child processes get their own
resources or they share with the parent
• The parent can either:
– Execute concurrently with children
– Wait until some or all children have
terminated using wait( ) system call
Process Creation
• Parent processes can create child
processes
– Using a fork( ) system call: copy of
parent
– Or by specifying the new process
• Parent must know the child’s process
id
Process Termination
• A process uses the exit( ) system call to ask
the O.S. to terminate it
• Resources are deallocated: memory, files,
buffers
• A parent can ask to have a process killed by
using the abort( ) system call
Cooperating Processes
• Reasons for processes which can affect
each other to cooperate:
– to share information
– to execute faster
– to make more modular
• There must be ways then, for processes to
communicate --> IPC
Cooperating Processes
• Producer-Consumer
– Unbounded buffer
• No limit on buffer size
• Producer can always produce
– Bounded buffer
• Consumer waits if buffer is empty
• Producer waits if buffer is full
– See code pp. 108 -109
Interprocess Communication
• Needs two operations:
– send( )
– receive( )
• Needs a communication link
–
–
–
–
How are links established?
Are links associated with >2 processes?
What is capacity of link?
Unidirectional or bidirectional?
Interprocess Communication
• Buffering: what is the capacity of the link?
– Zero: no messages waiting
– Bounded: there is a queue with finite length
– Unbounded: any number of messages can wait;
sender is never delayed
• Should sent messages be acknowledged?
• What about lost messages?
Client-Server Communication
• Sockets
– A pair of processes communicating over a
network uses sockets
– A socket consists of an IP address and a port
number
– Typically a server waits and listens for an
incoming request at a specific port
– A connection is made when the server accepts a
connection request
Client-Server Communication
• Some ports are well-known and under 1024
– ftp (port 21)
– telnet (port 23)
– http (port 80)
• Other ports are assigned when a client process
requests a connection
– The host assigns it a port of a number > 1024
– The connection consists of the pair of sockets:
(serverIP:port) and (hostIP:port) on the host
– See Figures 4.9, 4.10, and 4.11
Client-Server Communication
• Remote Procedure Calls
– Used for message-based communication between
processes executing on separate systems
– A port is a number which is used for addressing
messages
– Remote systems can obtain information by sending an
RPC to that port number
– See Figure 4.12
– RMI is the Java version of an RPC