netw 3005. reading for this lecture, you should have read chapter 2 (sections 1-9). netw3005...

42
NETW 3005

Upload: donald-gibbs

Post on 02-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

NETW 3005

Page 2: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Reading

• For this lecture, you should have read Chapter 2 (Sections 1-9).

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 2

Page 3: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Last lecture

• History and types of operating systems:– batch systems, multiprogramming systems,

time sharing systems, etc.

• Operating system tasks:– process management, storage

management, I/O device management, user interface.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 3

Page 4: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

This lecture

• Hierarchical Structure in Operating Systems

• System calls and interrupts

• Representing processes in Operating Systems

• Overview of process scheduling.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 4

Page 5: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Hierarchical structure in OS

• An operating system, like any complex computer system, must be carefully designed.

• One central requirement is modularity.

• Distinction between system programs and application programs.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 5

Page 6: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 6

Application programs

System programs

Kernel operations

Device drivers

Terminal drivers

Memory manager

Page 7: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Application programs

• Ones that ordinary users interact with:– Word-processors– Database packages– Web browsers– Compilers, editors, IDEs, etc– . . .

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 7

Page 8: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

System programs

• Provide a general-purpose lower-level function. System functions include:– file manipulation: create, delete, copy etc.– status info: date, available memory.– program loading and execution.– communication between processes.– Command interpreters (a.k.a. shell

programs). The set of system programs define the user interface.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 8

Page 9: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Other system functions

• Not strictly part of the OS, but often packaged with it.

• Programs to modify files (text editors, search, transform).

• Compilers, assemblers and interpreters.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 9

The set of system programs defines the user interface.

Page 10: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Degrees of modularity

• Different operating systems enforce different degrees of modularity.

• Ideally you want to oblige all system and application programs to talk to the hardware via the kernel.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 10

Page 11: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

MS-DOS

NETW3005 (Operating Systems) 11COSC 243 (Operating Systems) 11

System programs

Kernel operations

Device drivers

Terminal drivers

Memory manager

Application programs

Lecture 02 - System Structure & Processes

Page 12: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Talking to the kernel: system calls

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 12

System Program

Kernel

Hardware

‘‘read from the keyboard’’ ‘‘open a file’’‘‘write to the screen’’

Page 13: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

System calls

• Written in the same language as kernel (typically C).

• Available to Assembler and (at least) some HLLs — C, Perl, etc.

• The set of system calls is termed the programmer interface to the system.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 13

Page 14: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

A simple system program — copy

• cp file1 file2

• Open file1; Create file2.

• Loop: Read from file1; Write to file2.

• Close file1; Close file2.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 14

Page 15: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Types of system call (1)

• Process control– create, terminate, suspend, resume, abort.

• File manipulation– open, close, read, write

• Device manipulation– request, release, read, write.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 15

Page 16: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Types of system call (2)

• Housekeeping– get/set time or date– get/set attributes (process, device, file)

• Communications– set up link,– send/receive message

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 16

Page 17: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

InterruptsHow system calls are implemented

• CPU responds to interrupts no matter what else it happens to be doing.

• An interrupt transfers control to an appropriate module in the kernel.

• A system call transfers control to the kernel by generating an interrupt (sometimes called a trap in this context).

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 17

Page 18: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Responding to an interrupt

• Effectively a Jump to Subroutine: – current instruction address (PC) is saved– control transferred to fixed address,

depending on the interrupt.

• The interrupt vector is an array of locations that hold the addresses of these routines, usually held in low memory.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 18

Page 19: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Implementation issues

• How do we guarantee that the interrupt-handing routine won’t affect the interrupted process?

• What happens if an interrupt occurs while an interrupt-handling routine is executing?

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 19

Page 20: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Virtual machines

• System calls allow the OS to hide the low-level hardware from application programs.

• In a virtual machine these system calls are executed by a program which emulates the hardware.

• This hardware may, or may not be the same as the actual hardware.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 20

Page 21: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 21

processes

hardware

kernel

processes processes processes

kernel1 kernel2 kernel3

hardware

VM1 VM2 VM3

virtual-machine implementation

Page 22: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Benefits of virtual machines

• Protection: users aren’t even aware there are other users.

• Good for operating systems R & D. (No down-times: just give a system programmer her own virtual machine.)

• A way of solving system-compatibility problems.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 22

Page 23: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Problems with virtual machines

• Speed: virtual machines are slower.

• Implementation is very difficult, e.g. resource allocation (particularly disc).

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 23

Page 24: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Java

• Compiled Java code is called byte-code.

• It is designed to run on the Java Virtual Machine (JVM).

• Think about the command-line process of compiling and running a Java program as opposed to compiling and running a C++ program.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 24

Page 25: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Processes

• Recall: a process is not just a program – it is a dynamic entity.

• A given program (e.g. emacs) could be executing many times on a given machine – the machine must represent each execution as a separate process.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 25

Page 26: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Components of a process (1)

• Code section: the program code itself

• Data section: any global variables used by the program

• Process stack: any local variables currently being used (subroutine parameters, return addresses, etc.)

• Program counter: a pointer to some place in the program code.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 26

Page 27: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Components of a process (2)

• Contents of CPU registers.

• Memory management information.

• Accounting information: who owns the process, how long it’s been running, how much CPU time it’s used so far, etc.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 27

Page 28: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Process state

• The operating system keeps track of the state of each process.

• A process can be in any of the following states:– new– running– waiting/blocked– ready– terminated

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 28

Page 29: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

An Example from MacOS X

oucs1046: chandley$ ps –ax

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 29

Page 30: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Macos X processes (1)

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 30

PID TTY TIME CMD 1 ?? 1:26.15 /sbin/launchd10 ?? 0:03.03 /usr/libexec/kextd11 ?? 1:06.37 /usr/sbin/DirectoryService12 ?? 0:27.57 /usr/sbin/notifyd13 ?? 15:11.87 /usr/sbin/syslogd14 ?? 2:08.74 /usr/sbin/configd15 ?? 0:18.55 /usr/sbin/distnoted16 ?? 25:23.28 /usr/sbin/mDNSResponder –launchd20 ?? 0:03.56 /usr/sbin/securityd -i

Page 31: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Macos X processes (2)

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 31

24 ?? 1:24.42 /usr/sbin/ntpd -n -g -p …25 ?? 0:02.00 /usr/sbin/cron26 ?? 17:58.14 /usr/sbin/update27 ?? 0:00.01 /sbin/SystemStarter31 ?? 0:00.03 /System/Library/CoreServices/…

Page 32: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Macos X processes (3)

• Produced 75 different processes.

• Several distinct classes– Daemons – security, cron, update, etc.– Core Services – Dock, Finder, etc.– Network and communications.– Application programs – Preview, Power-

Point, Word, Adobe Acrobat, etc.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 32

Page 33: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Scheduling: an overview

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 33

Disk Job2, Job2, Job3, Job4, …

CPU

Main Memory

O.S.

Process 1

Process 2

Process 3

Process 4

Page 34: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Types of scheduler

• Long-term scheduler (batch systems): decides which jobs loaded onto the disk should be moved to main memory.

• Short-term scheduler (a.k.a. CPU scheduler): chooses how to allocate the CPU between the processes which are ready to execute.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 34

Page 35: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Scheduling queues

• The relationships between processes are represented by the O/S as queues.– Job queue: all the processes in the system

(including those on disk).– Ready queue: all the processes which are

ready to execute.– Device queue: all the processes waiting to

use a particular device. (One queue per device.)

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 35

Page 36: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

The Flow of Processes in an OS

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 36

ready queue CPU

I/O request

I/O device queue

I/O device queue

I/O

I/O

fork

interrupt mechanism

Page 37: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Process creation

• A process is created (‘spawned’) by another process – we talk of parent and child processes.

• When you launch an application, the terminal process spawns the application process.

• Processes are able to ‘call’ other processes, just as a program can call functions.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 37

Page 38: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Differences

• A child process can (and often does) run concurrently with its parent.

• A child process needn’t be constrained to use the resources of its parent (although it may be, and often is).

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 38

Page 39: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

A process tree (1)

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 39

root

daemons init

user1 user2 user3

system proc application

child child

Page 40: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

A process tree (2)

• Note that users are treated as processes by the operating system.

• How does that work?

• Answer: users are really represented to the system as shell processes.

• An important notion: the root user.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 40

Page 41: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Homework

• The Unix command ps displays information about processes on the system. Read the man page for ps (i.e. do “man ps”), and try out some of the options.

NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes 41

Page 42: NETW 3005. Reading For this lecture, you should have read Chapter 2 (Sections 1-9). NETW3005 (Operating Systems) Lecture 02 - System Structure & Processes2

Next Lecture

Threads and Data SharingChapter 4 (Sections 1-4)