Download presentation
Presentation is loading. Please wait.
1
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 3: Processes
2
3.2 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 3: Processes What is a process? How are procs scheduled? What are allowable operations on procs? How do procs cooperate or conflict? How do procs communicate with each other?
3
3.3 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Concept Process – a program in execution Process Control Block (PCB) for each proc CPU registers and program counter Stack Static data CPU scheduling info Memory-management info Accounting info I/O status info Process state
4
3.4 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Control Block (PCB)
5
3.5 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process in Memory
6
3.6 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process State 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 Kernel service like i/o or authentication ready: The process is waiting its turn to run terminated: The process has finished execution
7
3.7 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 State Transition Diagram for Procs, ver. 1 Page 87, Fig. 3.2
8
3.8 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 CPU Switch From Process to Process Page 89, Fig. 3.4
9
3.9 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Scheduling Queues Job queue – set of all procs in the system Ready queue – set of all procs waiting to execute Device queues – set of procs waiting for an I/O device Processes migrate among the various queues
10
3.10 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Ready Queue And Various I/O Device Queues
11
3.11 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Schedulers Long-term scheduler (or job scheduler) Which procs should be brought into the ready queue? Short-term scheduler (or CPU scheduler) Which proc should be executed next and on which CPU? Long-term scheduler Short-term scheduler
12
3.12 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Representation of Process Scheduling
13
3.13 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Medium Term Scheduler (Swapper)
14
3.14 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Schedulers (Cont.) Short-term scheduler is invoked frequently (millisecs) (fast) Long-term scheduler is invoked infrequently (secs, mins) (slow) Long-term scheduler controls “degree of multiprogramming” Procs are either I/O-bound – more time in I/O than computing; many, short CPU bursts CPU-bound – more time computing than I/O; few, long CPU bursts
15
3.15 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Context Switch Kernel CPU time to switch to another proc: Save state of old proc, load saved state of new proc Context-switch is overhead, not useful work Modern CPUs have hardware support E.g. Sun SPARC register window http://www.extremetech.com/article2/0,1697,1158259,00.asp
16
3.16 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Creation Parent procs create children, forming a tree of procs Resource sharing: some, all, or none Execution: concurrently or parent wait Address space: duplicate or separate UNIX system call example: fork creates new proc exec after a fork replaces proc’s memory with a new program
17
3.17 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Creation in POSIX Page 97, Fig. 3.10
18
3.18 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Creation in Win32
19
3.19 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Creation in Java
20
3.20 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Termination Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent (via wait) Process’ resources are deallocated by operating system Parent may terminate execution of children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination
21
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 End of Day 8 Lecture Read to p. 116 in Chapter 3 Come to Frey 366 Lab
22
3.22 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Reminders (Day 10) Show ProcessExplorer on Windows. Quiz: Give an example for each of these three things: 1. A file system that always uses a B-tree. 2. A file system that has always been stateful. 3. A file system that supports journaling.
23
3.23 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Interprocess Communication Message PassingShared Memory
24
3.24 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Producer-Consumer Problem Paradigm for cooperating processes, producer proc produces information that is consumed by a consumer proc unbounded-buffer -- no practical limit on size of buffer bounded-buffer -- fixed buffer size
25
3.25 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Sharing Memory in Java
26
3.26 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer: Shared-Memory Solution Page 102, Fig. 3.15
27
3.27 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer: Shared-Memory Solution (cont.) Page 104, Fig. 3.18
28
3.28 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer: insert() method Page 103, Fig. 3.16
29
3.29 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer: remove() method Page 103, Fig. 3.17
30
3.30 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Message Passing: General Procs communicate without shared variables Operations: send (message) – message size fixed or variable receive (message) P and Q communicate, establishing a link, exchanging messages via send/receive Implementation of link physical (e.g., shared memory, hardware bus) logical (e.g., queue)
31
3.31 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Message Passing Implementation How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional?
32
3.32 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Strategy #1: Direct Communication Processes name each other explicitly: send (P, message) – send message to proc P receive (Q, message) – receive message from proc Q Links established automatically Link associated with one pair of procs Between each pair there exists exactly one link Link is unidirectional, or more commonly bi-directional
33
3.33 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Strategy #2: Indirect Communication Messages through queues called mailboxes or ports ( ls | more or FTP on port 21) Each mailbox has a unique id Procs communicate by sharing mailbox Properties of mailboxes May be associated with many procs Procs may share many mailboxes Mailboxes be unidirectional or bi-directional
34
3.34 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Indirect Communication (cont.) Operations create a new mailbox destroy a mailbox send and receive send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A
35
3.35 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Indirect Communication (cont.) Mailbox sharing P 1, P 2, and P 3 share mailbox A P 1, sends; P 2 and P 3 receive Who gets the message? Solutions Allow a link to be associated with at most two procs Allow only one proc at a time to execute a receive operation Allow OS to select arbitrary receiver. Sender is notified who receiver was.
36
3.36 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Synchronization of message passing Blocking is synchronous Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available Non-blocking is asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null
37
3.37 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Buffer capacity Queue of messages attached to the link: either 1.Zero capacity – 0 messages. Sender must wait for receiver (“rendezvous”). 2.Bounded capacity – n messages. Sender must wait if link full. 3.Unbounded capacity – infinite length Sender never waits.
38
3.38 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer: Message Passing Solution Page 109, Fig. 3.20
39
3.39 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer – Message Passing Solution Page 109, Fig. 3.21
40
3.40 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer – Message Passing Solution The Producer Page 110, Fig. 3.22
41
3.41 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Bounded-Buffer – Message Passing Solution The Consumer Page 110, Fig. 3.23
42
3.42 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 LPC Message Passing, WinXP, 3 ways Page 113, Fig. 3.24
43
3.43 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Client-Server Communication Sockets (TCP/IP or UDP/IP on any port) RPC (Remote Procedure Calls) RMI (Remote Method Invocation, Java)
44
3.44 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Sockets A socket is an endpoint for communication The socket 146.86.5.20:1625 refers to port 1625 on host 146.86.5.20 Page 114, Fig. 3.25
45
3.45 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Socket Communication in Java Page 115, Fig. 3.26
46
3.46 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Socket Communication in Java (cont.) Page 116, Fig. 3.27
47
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 End of Day 10 lecture Finish reading Chapter 3
48
3.48 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Remote Procedure Calls (RPC) Abstracts calls between procs across networks. Stubs – client-side proxy for the remote proc. The stub locates the server (the “matchmaker daemon”) and marshalls the parameters. Server-side receives this message, unpacks the marshalled parameters, performs the proc, and returns a value to the client.
49
3.49 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Execution of Remote Procedure Call Page 119, Fig. 3.28
50
3.50 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Remote Method Invocation (RMI) A Java mechanism similar to RPCs: A program on one machine invokes a method on a remote object, including passing object parameters that implement java.io.Serializable
51
3.51 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Marshalling Parameters
52
3.52 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 RMI Example
53
3.53 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 RMI Example
54
3.54 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 RMI Example
55
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 End of Chapter 3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.