thursday, june 08, 2006 the number of unix installations has grown to 10, with more expected. the...

27
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Thursday, June 08, 2006

The number of UNIX installations has grown to 10, with more expected.

The UNIX Programmer's Manual, 2nd Edition, June, 1972

Page 2: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Completion of I/O triggers an interruptHardware Trap:

Division by zero Invalid memory access

Request for OS service Trap/System call/Monitor call

Page 3: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Protection

Dual Mode Operation User mode Kernel mode

Mode bit (0/1) (MS-DOS did not have it)System call (switches from user mode to

kernel mode)Privileged instructions should be

executed in kernel mode only

Page 4: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Protection

Changing mode bit?

Page 5: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

I/O Protection

User cannot issue I/O instructions directly

Changes to interrupt vector?

Page 6: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Memory Protection

Page 7: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Memory Protection

Page 8: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Memory Protection

Changes to base and limit registers?

Page 9: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

CPU Protection

E.g. Infinite loop executed by a process

Page 10: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

CPU Protection

Timer handler?

Page 11: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process :Program in execution

Associated state (PC, SP, registers etc)

Address space

Page 12: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

ProcessesThe Process Model

Multiprogramming of four programsConceptual model of 4 independent, sequential processesOnly one program active at any instant

Logical program counter

Execution order not reproducible

Page 13: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process creation• System initialization

• User request to create a new process

Page 14: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process Termination

Conditions which terminate processes

1. Normal exit (voluntary)

2. Error exit (voluntary)

3. Fatal error (involuntary)

4. Killed by another process (involuntary)

Page 15: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process Hierarchies

Parent creates a child process, child processes can create its own process

Forms a hierarchy UNIX calls this a "process group"

Windows has no concept of process hierarchy all processes are created equal

Page 16: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a

processor terminated: The process has finished execution

Page 17: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process States

ps in Unix

Background processes

Page 18: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process Control Block (PCB)

Page 19: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

CPU Switch From Process to Process

Page 20: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process Scheduling Queues

Job queue – set of all processes in the systemReady queue – set of all processes residing in main

memory, ready and waiting to executeDevice queues – set of processes waiting for an I/O

deviceProcesses migrate among the various queues

Page 21: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Ready Queue And Various I/O Device Queues

Page 22: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Representation of Process Scheduling

Page 23: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

I/O parallelism:

overlap execution: make 1 CPU into many (Real parallelism: > 1 CPU (multiprocessing))

Completion time:

B’s completion time = 100s (A + B) So overlap

Why processes? Speed

emacs (Wait for input) (Wait for input)

gcc

A B

A

B

20 s80 s

Completion time for B? A?10 s

Page 24: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Context Switch

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process

Context-switch time is overhead; the system does no useful work while switching

Time dependent on hardware support

Page 25: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972
Page 26: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Passing of Parameters As A Table

Page 27: Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972

Process Creation (Cont.)

Address space Child duplicate of parent Child has a program loaded into it

UNIX examples fork system call creates new process exec system call used after a fork to replace

the process’ memory space with a new program