Download Slides for week 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Distributed operating system wikipedia , lookup

Unix security wikipedia , lookup

DNIX wikipedia , lookup

CP/M wikipedia , lookup

Burroughs MCP wikipedia , lookup

VS/9 wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
I/O Devices

Controller: physically controls the devices

Devices are diverse and complicated

Present simpler interface to OS

E.g, convert a linear sector number to number of
cylinder, sector and head.
Operating system


Device driver: software talks to a
controller
Installation of drivers

Re-link kernel with new driver, reboot

Register driver in system file, reboot

Install on-the-fly, PNP, NO reboot
driver
controller
device
1
Handle I/O: Busy Waiting
User program
Kernel
Driver
I/O
device
Issue a system call
(TRAP)
Call driver
T
I
M
E
Start I/O
CPU
Wasted
Polling
Do I/O
Put data
Return control to
caller
Continue
2
An Example
// p is the buffer
for (i=0; i<count; i++){
while (*printer_status_reg!=READY);
*printer_data_register=p[i];
}
return_to_user();
// loop on every character
// loop until ready
// output one character
3
I/O by Interrupt




Driver tells controller what to do by writing its device
registers. Then the controller starts the device.
Controller finishes reading/writing, and then signals the
interrupt controller
If interrupt controller can accept the interrupt, it informs
CPU
Interrupt controller puts the number of device on the bus,
CPU read it
Disk drive
CPU
Interrupt controller
Disk controller
3
4
2
1
4
Interrupt-Driven I/O
Print system call
enable_interrupts();
*printer_data_register=p[0];
scheduler();
Interrupt service procedure
Interrupt occurs on
every character!
if (count==0){
unblock_user();
} else {
*printer_data_register=p[I];
count--;
i++;
}
acknowledge_interrupt();
return_from_interrupt();
5
Direct Memory Access (DMA)
User program
Kernel
I/O device &
memory
Issue a system call
Set up DMA chip
Suspended
Run other
programs
I/O directly
Issue interrupt when
finish
Set the program
status as “ready”
Ready to continue
6
I/O Using DMA


Too many interrupts in interrupt-driven
I/O
DMA reduces # of interrupts from
1/char to 1/buffer printed
Print system call
copy_from_user(buffer, p, count);
set_up_DMA_controller();
scheduler();
Interrupt service procedure
acknowledge_interrupt();
unblock_user();
return_from_interrupt();
7
Advanced Computer With Multiple Buses
Cache bus Local bus
Level 2
cache
CPU
Memory bus
PCI
bridge
Main
memory
PCI bus
SCSI
SCSI bus Mouse
Modem
USB bus
ISA
USB
bridge
Keyboard
Sound card
IDE bus
IDE
disk
Available
Graphics PCI slot
adaptor
ISA bus Monitor
Printer
Available
ISA slot 8
Chapter 2
Processes and Threads
Outline





Processes
Threads
Inter-process communication (IPC)
Classical IPC problems
Scheduling
10
Process

A program in execution





a single instance of an executable program
User enters a command, invokes a program, while
this program is executing it is called a process
E.g, when a user types the command “ls” , the
UNIX system creates a process for this command.
Different processes running different
programs: Word, Excel
Different processes running same programs:
multiple web-browsers in a PC
11
Much More Than A Program

Address space




contain the executable program,
program’s data, and its stack.
the
I/O devices associated
Files opened
Execution State:

Registers, e.g., PC, PSW, SP, …
12
Process Vs. Programs: An Analogue
A baker (CPU) uses a recipe (program) to
transform the baking ingredients (input
data), with the aid of cooking utensils
and appliances (resources), into a cake
(output). We recognize this entire
activity as the process - an abstraction
of an executing recipe.
13
Process Vs. Program

Program is a script, while process is an
activity (execution) based on this script.


Cake recipeprogram, baking cake based
on the recipeprocess
Different processes may share the same
program


One copy of script, but multiple executions
Process is more than a script

Script, input, output, state, etc.
14
Information About Process

Process table in operating systems



Core image: process address space


One entry for each process in existence
Process ID, program counter, working
directory, registers, etc.
Instruction codes and data
Process information = Process table
entry + core image
15
Interleaving Execution of Processes


More than one process exist.
CPU switches from process to process.
Process
Process
Process
Process
Process
Process
A
B
A
C
B
C
Time
Process
switching
Which process to run next?
16
Pseudo-parallelism


At any instant, the CPU is running only one
process.
In the course of 1 second, it may work on
several different processes.



The illusion of parallelism
The true hardware parallelism: multi-processor
Multi-programming

CPU switches back and forth between processes.
17
Different Points of View
From
Running independently of each other.
Each process has its own logical program counter
(PC). But only one physical PC in CPU.
User
A
OS
Process
From
B
C
D


D

C


B


A 
t1
Time 
E
18
Process Creation – When?




System initialization
Created by another process
User request
Initialization of a batch job
19
Process Creation in System Initialization

Foreground processes



Interact with users
E.g., UNIX shell
Background processes


Not associated with particular user
Daemons: have some specific functions

E.g., Accepting emails, accepting web page
request
20