1
CPSC 410--Richard Furuta 01/19/99 1
Silberschatz and Galvin
Chapter 4 Processes
CPSC 410--Richard Furuta 01/19/99 2
Silberschatz and Galvin Chapter 4 Processes CPSC 410--Richard - - PDF document
Silberschatz and Galvin Chapter 4 Processes CPSC 410--Richard Furuta 01/19/99 1 Chapter overview Introduction to processes, process control blocks Introduction to process scheduling Operations on processes Cooperating
CPSC 410--Richard Furuta 01/19/99 1
CPSC 410--Richard Furuta 01/19/99 2
CPSC 410--Richard Furuta 01/19/99 3
CPSC 410--Richard Furuta 01/19/99 4
CPSC 410--Richard Furuta 01/19/99 5
CPSC 410--Richard Furuta 01/19/99 6
CPSC 410--Richard Furuta 01/19/99 7
CPSC 410--Richard Furuta 01/19/99 8
CPSC 410--Richard Furuta 01/19/99 9
admitted interrupt scheduler dispatch exit I/O or event wait I/O or event completion
CPSC 410--Richard Furuta 01/19/99 10
CPSC 410--Richard Furuta 01/19/99 11
Ð Process state Ð Program counter: next instruction to be executed Ð CPU registers: accumulators, index registers, stack pointers, general purpose registers, condition codes Ð CPU scheduling information: priorities, queue pointers, etc. Ð Memory-management information: base and limit registers, page/segment tables Ð Accounting information: resources used, account numbers, etc. Ð I/O status information: allocated devices, open files, etc. Ð Other information: process id, parentÕs id, configuration info., etc.
CPSC 410--Richard Furuta 01/19/99 12
CPSC 410--Richard Furuta 01/19/99 13
¥ Process unique identifier ¥ current state of process ¥ pointer to processÕ parent ¥ space to save needed values like program counter, CPU registers, current addressing mode (user/supervisor) when process is swapped ¥ CPU scheduling information (e.g., priority, scheduler data structures) ¥ memory management information (e.g., limit registers, page tables) ¥ pointers to allocated resources. I/O status information (e.g., devices, list of open files) ¥ accounting information (CPU time used, wall clock time used, time limits, account numbers, etc.) ¥ Configuration information (e.g., processor process is running on, etc.)
CPSC 410--Richard Furuta 01/19/99 14
CPSC 410--Richard Furuta 01/19/99 15
8 4 47 10 20 9
CPSC 410--Richard Furuta 01/19/99 16
CPSC 410--Richard Furuta 01/19/99 17
CPSC 410--Richard Furuta 01/19/99 18
CPSC 410--Richard Furuta 01/19/99 19
admitted interrupt scheduler dispatch exit I/O or event wait I/O or event completion
CPSC 410--Richard Furuta 01/19/99 20
¥ Short-term scheduler Ð may be executed frequently (every 100 milliseconds or so) Ð must be very fast ¥ Long-term scheduler Ð executes infrequently (perhaps minutes between executions) Ð can afford to take longer to make decisions Ð can take characteristics of process into account (I/O bound or CPU bound) Ð Goal: to obtain a good process mix of I/O and CPU bound processes Ð controls degree of multiprogramming ¥ Degree of multiprogramming: number of processes in memory
CPSC 410--Richard Furuta 01/19/99 21
CPSC 410--Richard Furuta 01/19/99 22
CPSC 410--Richard Furuta 01/19/99 23
CPSC 410--Richard Furuta 01/19/99 24
CPSC 410--Richard Furuta 01/19/99 25
CPSC 410--Richard Furuta 01/19/99 26
CPSC 410--Richard Furuta 01/19/99 27
CPSC 410--Richard Furuta 01/19/99 28
CPSC 410--Richard Furuta 01/19/99 29
CPSC 410--Richard Furuta 01/19/99 30
CPSC 410--Richard Furuta 01/19/99 31
#include <stdio.h> main() { int pid; char ch; int i, j; pid = fork(); if(pid) ch = 'a'; else ch = 'b'; for(i=1;i<=25;i++) { fputc(ch,stdout); fflush(stdout); for(j=1;j<100000;j++) ; } if(pid) { wait(); fputc('\n', stdout); } }
CPSC 410--Richard Furuta 01/19/99 32
bbbabbaabbbaaabaabbaabbabbbaaabbaabbbaaabaaabbaaba bbbbbbbaaaaaaabbbabaaabbbaabbbabbaabbaaabababaaaba bbaaaaaaaaaaaaaabbbbbbbbbbaaabbbabbbaabbaabaaabbbb aaaaaaaaaaaaaabbbbbbabbbaabababbbaaabbbaaabbbbbbbb bbbabbaaabbaaabaabbaabbbabbaaabaabbaaabbbbbaabbaaa bbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaabbbaaabaabbaaab aaaaaabbbbabbbaaabbbaabbabbbaabbaaaaabbbaaabbababb bbbbbbaaabbaaabbaabaaabbbabbabbbabbbaabaaabaabaaaa bbbbabaaabbbaaabbaabbbaaabaaabbbaabbaaabbaabbbaaab bbbbbbbbbbbbbbbbaaaaaaaaaaaaaababbaabbaaabbbaabaaa bbbbbaaaabbaaabbbaabbbaaabaabaabbbabbaabbaaabbaaba bbbbbbbbaaaaaabbbaabbaaabaaabbababbaaabbaabbbaaaba
CPSC 410--Richard Furuta 01/19/99 33
CPSC 410--Richard Furuta 01/19/99 34
CPSC 410--Richard Furuta 01/19/99 35
CPSC 410--Richard Furuta 01/19/99 36
CPSC 410--Richard Furuta 01/19/99 37
CPSC 410--Richard Furuta 01/19/99 38
CPSC 410--Richard Furuta 01/19/99 39
CPSC 410--Richard Furuta 01/19/99 40
CPSC 410--Richard Furuta 01/19/99 41
CPSC 410--Richard Furuta 01/19/99 42
CPSC 410--Richard Furuta 01/19/99 43
CPSC 410--Richard Furuta 01/19/99 44
CPSC 410--Richard Furuta 01/19/99 45
CPSC 410--Richard Furuta 01/19/99 46
Ð Requires register set switch but no memory management
Ð but scheduling can be unfair because OS doesnÕt know about multiple threads Ð entire process may have to wait if kernel not multi-threaded
CPSC 410--Richard Furuta 01/19/99 47
¥ States: ready, blocked, running, terminated ¥ Share CPU, only one thread at a time is running ¥ Thread executes sequentially ¥ Thread has own stack and PC ¥ Thread can create child threads ¥ If one thread blocked for system call, another can run ¥ Threads not independent because can access any address in task. No protection between threads because they are assumed to be cooperating, not hostile (as with traditional processes). ¥ Process synchronization mechanisms still required
CPSC 410--Richard Furuta 01/19/99 48
CPSC 410--Richard Furuta 01/19/99 49
¥ Solaris 2 thread categories Ð User-level threads (kernel has no knowledge of these) Ð Lightweight processes (LWP) ¥ One or more user-level threads associated with a LWP ¥ User-level thread cannot accomplish work if not connected to LWP ¥ Others either are blocked or waiting for a LWP Ð Kernel-level threads ¥ Exactly one kernel-level thread associated with each LWP ¥ Other kernel-level threads as well for other kernel functions ¥ On request, kernel-level thread can be pinned to a specific processor (only that thread runs on processor and the processor is allocated to that thread)
CPSC 410--Richard Furuta 01/19/99 50
CPSC 410--Richard Furuta 01/19/99 51
CPSC 410--Richard Furuta 01/19/99 52
CPSC 410--Richard Furuta 01/19/99 53
CPSC 410--Richard Furuta 01/19/99 54
¥ many applications fit sequential flow of information model naturally ¥ keeps processes totally separate except for messages Ð less error prone implementation ¥ no invisible side effects ¥ processes canÕt mess with each othersÕ memory (also added security) ¥ permits separation of implementation and enforcement of well- defined interfaces Ð separation especially appropriate when proceses cannot ÒtrustÓ each other (e.g., OS and user process) Ð permits distribution of processes, even across different kinds of processors on a network
CPSC 410--Richard Furuta 01/19/99 55
CPSC 410--Richard Furuta 01/19/99 56
while(true) { produce data in nextp send(consumer, nextp); }
while(true) { receive(producer, nextc); consume data in nextc }
CPSC 410--Richard Furuta 01/19/99 57
CPSC 410--Richard Furuta 01/19/99 58
CPSC 410--Richard Furuta 01/19/99 59
CPSC 410--Richard Furuta 01/19/99 60
¥ High-level concept for process communication ¥ ProgrammerÕs view is the same as for regular procedure calls ¥ Each RPC is implemented as a pair of synchronous send and receive statements Ð first pair transmits (and acknowledges) input parameters Ð second pair acquires (and acknowledges) corresponding results ¥ Another viewof same process: remote procedure in implementation Ð begins with a receive to acquire actual parameters Ð ends with a send to provide results to caller ¥ Sun RPC encapsulates these in an event-driven structure Ð Remote procedures are implemented as set of handlers that are executed as called