processes csci 4534 chapter 4. introduction early computer systems allowed one program to be...

21
Processes CSCI 4534 Chapter 4

Upload: homer-matthews

Post on 13-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 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

Processes

CSCI 4534

Chapter 4

Page 2: 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

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”

Page 3: 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

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.

Page 4: 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

Introduction

• Main concerns of an operating system:– To execute user programs– To execute system programs

Page 5: 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

Process States

• New

• Ready

• Running

• Waiting

• Terminated

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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

Page 10: 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

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

Page 11: 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

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

Page 12: 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

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

Page 13: 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

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

Page 14: 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

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

Page 15: 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

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

Page 16: 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

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

Page 17: 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

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?

Page 18: 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

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?

Page 19: 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

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

Page 20: 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

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

Page 21: 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

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