+ All Categories
Home > Documents > Process Management Operating Systems Lecture 3, 27 March 2003 Mr. Greg Vogl Uganda Martyrs...

Process Management Operating Systems Lecture 3, 27 March 2003 Mr. Greg Vogl Uganda Martyrs...

Date post: 31-Dec-2015
Category:
Upload: hubert-reynolds
View: 218 times
Download: 3 times
Share this document with a friend
39
Process Management Operating Systems Lecture 3, 27 March 2003 Mr. Greg Vogl Uganda Martyrs University
Transcript

Process Management

Operating Systems

Lecture 3, 27 March 2003

Mr. Greg Vogl

Uganda Martyrs University

27 March 2003 Operating Systems: Process Management

2

Overview

1. Monolithic kernel vs. microkernel (lecture 1)

2. Program, Process, Thread

3. Interrupts

4. Process States

5. Process Scheduling

6. Processes in UNIX

7. Processes in Windows

27 March 2003 Operating Systems: Process Management

3

1. Monolithic Kernel

27 March 2003 Operating Systems: Process Management

4

Microkernel

27 March 2003 Operating Systems: Process Management

5

2. Program

Series of commands

Instructions only (usually not data)

Stored on disk, copied into memory

Can be in use by many users and processes at the same time

Also called software Includes shell scripts, batch files

27 March 2003 Operating Systems: Process Management

6

Process

Variables point to instructions + data

Loaded in memorycontext contains all process state info.stored in Process Control Block

One user and one program per process

Also called task (or job for batch processes)

27 March 2003 Operating Systems: Process Management

7

Process Context

program counter register indicating next program instruction to run

other registers accumulator, index/address, status, general

stack of subroutine return addresses subroutines call other subroutines

values of local and global variables pointers to open data files

user and terminal number (in multi-user OS)

27 March 2003 Operating Systems: Process Management

8

Examples of Processes

User ProcessesShellsText editors, databasesBackground jobs (end with & in UNIX)

System ProcessesMemory management, process schedulingdaemons (system background processes)

Mail and print servers

27 March 2003 Operating Systems: Process Management

9

Thread

Also called sub- or lightweight processLittle private memory; memory is sharedSubdivides work of the processThreads are managed by the process Reduces high overhead for creating processes and context switchingJava was designed to write thread-based programs

27 March 2003 Operating Systems: Process Management

10

Thread Components

At minimum, every thread has its ownprogram counterstack

Program text shared with other threads

Each procedure has a frame to hold its local variables

Heap of objects is shared by all threads

27 March 2003 Operating Systems: Process Management

11

Uses of Threads

Servers (database, mail, print, etc.)one thread per client request

Network serverone thread per connection

Time-sharing one thread per user

Real-time factory controlone thread per device

27 March 2003 Operating Systems: Process Management

12

3. Interrupt

Signal hardwareCPU requesting services CPU postpones its work to handle interrupt

Interrupt handler routines are part of OS code OS switches modes (usersupervisor)

Interrupts are prioritised Stack used to store multiple interrupt levels

Programs can mask (ignore) some interrupts Others unmaskable (to avoid losing data)

27 March 2003 Operating Systems: Process Management

13

Examples of Interrupts

Key pressed

Disk or other I/O task finished

System clock

27 March 2003 Operating Systems: Process Management

14

Software Interrupts

Also called traps or exceptions

Processor interrupted by programs

ExamplesDivision by 0 errorBus errorArray out of boundsBuffer overflow

27 March 2003 Operating Systems: Process Management

15

Context Switching

Preserve state of current process

Start or re-start another process

Performed by dispatcher (OS component)

When to change context?Overhead cost (takes CPU time)Processes prioritised by properties

27 March 2003 Operating Systems: Process Management

16

4. Process States

Runnable Running (only one per processor) Ready (waiting for its turn to run)

Blocked Explicit e.g. wait() until a child terminates Implicit e.g. read() Blocked by another process

New (not yet allowed to wait its turn)Suspended (e.g. swapped to virtual memory)Terminated (finished but still using resources)

27 March 2003 Operating Systems: Process Management

17

Process State DiagramRitchie p. 62

ready

running

blocked

ready suspended

blocked suspended

entry (HLS) I/O completion

I/O completion

suspend

resu

me

termination

I/O w

ait

(ML

S)

susp

end resum

e

(LLS) dispatch

timeout

susp

end

27 March 2003 Operating Systems: Process Management

18

5. Scheduling

Assign each process time to use CPUDetermine sequence (order), timing (when)Conflicting objectives need compromise

Scheduling levelsHigh: whether to admit a new processMedium: suspend/resume a processLow: dispatch (run) a ready process

27 March 2003 Operating Systems: Process Management

19

Scheduling Objectives

Maximise throughputGive all users a “fair” (not equal) chanceProvide tolerable performance Response time for on-line userTurnaround time for batch users

Degrade performance gracefullyOK to be slow but avoid complete collapse

Be consistent, predictable over time

27 March 2003 Operating Systems: Process Management

20

Scheduling Criteria

Priority which may be either/both: Assigned to job by user Determined by properties of the job

Class of job (real-time > on-line > batch)

Resources needed (CPU time, memory)

I/O or CPU bound (the aim is a balance)

Resources already used

Time already waited

27 March 2003 Operating Systems: Process Management

21

Types of Scheduling Policies

Preemptive (Used by most OS today)OS stops one process to run another

Non-preemptiveprocess runs until termination or I/O wait

Cooperative (Used by Windows 3.11)Programs must voluntarily give up CPUNot managed by OS; trusts programmers If a process hangs the whole PC hangs

27 March 2003 Operating Systems: Process Management

22

Scheduling Policies

First come first served (FCFS/FIFO)

Shortest job first (SJF)

Shortest remaining time (SRT)

Highest response ratio next

Round robin (RR)

Multi-level feedback queues (MFQ)

27 March 2003 Operating Systems: Process Management

23

First come first served

Also called first in first out (FIFO)

Process waiting longest is first in queue

Favours long jobshigh run-time/wait-time ratio

Favours CPU-bound jobs I/O devices underused

27 March 2003 Operating Systems: Process Management

24

Shortest job first (next)

Run job with shortest estimated run time

Long jobs may be delayed indefinitely

JCL commands can specify run time

27 March 2003 Operating Systems: Process Management

25

Shortest remaining time

Run job w/ shortest est. remaining time

Highly favours short jobs

Long jobs will be delayed indefinitely

Requires estimating total run time

Requires measuring elapsed run time

27 March 2003 Operating Systems: Process Management

26

Highest response ratio next

P = (time waiting + run time) / run time

Priority based on two factors

Favours shorter jobs

Guarantees a job cannot be starved

27 March 2003 Operating Systems: Process Management

27

Round Robin

Each process given a set time slicePre-emption at end of time quantum Hardware timer generates interrupts

After running, go to back of queueUsed in most interactive operating systemsHow large should each time slice be? Small high context switch overhead Large user response time is reduced In practice, about 10-20 ms

27 March 2003 Operating Systems: Process Management

28

Multi-level feedback queues

Separate queues for different prioritiesNew process level 1 FIFO (highest)After timeout level 2 FIFO, etc.Lowest level is Round Robin

Adapts to past process behaviourshigh CPU usage reduced access level

Long processes may starve if wait time is long, promote/increase slice

27 March 2003 Operating Systems: Process Management

29

6. UNIX process creation

PID 0: sched (process scheduler)

PID 1: init (ancestor of other processes)

daemons (automatic, for sys. admin.)

getty (one per terminal)

login (lets users log in)

shell (lets users run programs)

user-initiated processes (run from shell)

27 March 2003 Operating Systems: Process Management

30

UNIX fork()

fork() produces new “child” processChild is exact copy of parentStarts in same program, at same placeExact copy of memory space

(globals, stack, heap object)

Both calls to fork() return a valueParent fork() returns process ID of childChild fork() returns 0

27 March 2003 Operating Systems: Process Management

31

UNIX exec()

Execute (load, run) another program

Overwrite calling process in memory

Uses same PID; not a new process

Used after fork() to start new process

Parent waits for child process to finish

Run in background to not hold up shellmyprogram &

27 March 2003 Operating Systems: Process Management

32

UNIX scheduling

Varies with the flavour of UNIXOften dynamic priority, round robin, MFQ

Processes have number priority values0=highest, 60=lowest, 20=initial/default

Users can reduce priority using nicenice -10 myprog # makes priority 30

Only superuser can increase prioritynice --10 myprog # makes priority 10

27 March 2003 Operating Systems: Process Management

33

UNIX ps

Command to display process status

ps # list PIDs, TTYs, CPU time, name

ps -a # all terminal-created processes

ps -e # everything (incl. daemons)

ps -f # full list (more details)

ps -l # long list (ppid, priority, size, nice)

27 March 2003 Operating Systems: Process Management

34

Other UNIX commands

top – process list, continuously updated

jobs – list jobs running in current shell

bg, fg – send jobs to back/foreground

at – run batch job at specified time(s)

kill – send signal to terminate process

sleep – pause for some seconds

27 March 2003 Operating Systems: Process Management

35

7. Processes in Windows

Every process treated as thread

Process can create additional threads

Scheduler operates over all threads

Each process has virtual address space

No parent-child process relationship

Environment copied to new processes

27 March 2003 Operating Systems: Process Management

36

Dynamic Link Libraries (DLLs)

Executable code routines

Linked into application only at run time

Can be shared by several programs

27 March 2003 Operating Systems: Process Management

37

Starting Programs

Type program name (maybe full path)MS-DOS prompt, run dialog box, Explorer

Double-click iconDesktop, Explorer, My Computer

Click shortcutStart or Programs menu, QuickLaunch

Start when the computer startsautoexec.bat, config.sys, Startup menu

27 March 2003 Operating Systems: Process Management

38

Managing Tasks

Ways to close programsCtrl-C; File, Exit; Close button (X); Alt-F4

Press Ctrl-Alt-Del to view task managerEnd Task: stop non-responding programCtrl-Alt-Del again to shut down/restart

27 March 2003 Operating Systems: Process Management

39

WinMe System Information

Loaded modules (exe, dll, etc.)Name, version, size, file date, mfg., path

Running tasksName, path, PID, priority, version, size

Startup programsProgram, command, user name, location

Print jobs


Recommended