Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 4 PROCESSES Operating Systems CHAPTER FOUR, OPERATING SYSTEMS 2 Processes Current-day computer systems allow multiple programs to be loaded into.

Similar presentations


Presentation on theme: "CHAPTER 4 PROCESSES Operating Systems CHAPTER FOUR, OPERATING SYSTEMS 2 Processes Current-day computer systems allow multiple programs to be loaded into."— Presentation transcript:

1

2 CHAPTER 4 PROCESSES Operating Systems

3 CHAPTER FOUR, OPERATING SYSTEMS 2 Processes Current-day computer systems allow multiple programs to be loaded into memory and to be executed concurrently. This resulted in process, which is a program in execution. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

4 CHAPTER FOUR, OPERATING SYSTEMS 3 Process Concept An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks Even on a single-user system, such as Windows or Mac, a user may be able to run several programs at one time. Textbook uses the terms job and process almost interchangeably. Process – a program in execution; process execution must progress in sequential fashion. §4.1

5 CHAPTER FOUR, OPERATING SYSTEMS 4 Process Concept A process is more than the program code (known as the text section), it also includes the current activity represented by: program counter Stack – contains temporary data (such as method parameters, return addresses, and local variables) data section – contains global variables. A program is not a process; a program is a passive entity, such as the contents of a file stored on disk, whereas a process is an active entity, with a program counter specifying the next instruction to execute. §4.1.1

6 CHAPTER FOUR, OPERATING SYSTEMS 5 Process Concept Two processes associated with same program are considered two separate execution sequences. Ex: several users running different copies of the mail program or same user may invoke many copies of the editor program. Each of above is a separate process, and, although the text sections are equivalent, the data sections vary.

7 CHAPTER FOUR, OPERATING SYSTEMS 6 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. ready: The process is waiting to be assigned to a process. terminated: The process has finished execution. Only one process can be running on any processor at any instant. Many processes may be ready and waiting, however. §4.1.2

8 CHAPTER FOUR, OPERATING SYSTEMS 7 Diagram of Process State

9 CHAPTER FOUR, OPERATING SYSTEMS 8 Process Control Block (PCB) Information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information §4.1.3

10 CHAPTER FOUR, OPERATING SYSTEMS 9 Process Control Block (PCB)

11 CHAPTER FOUR, OPERATING SYSTEMS 10 CPU Switch From Process to Process

12 CHAPTER FOUR, OPERATING SYSTEMS 11 Process Scheduling Queues Job queue – set of all processes in the system. Ready queue – set of all processes residing in main memory, ready and waiting to execute. This queue is generally stored as a linked list. Device queues – Since there are many processes in the system, the device may be busy with other processes ’ requests. The list of processes waiting for a particular I/O device is called a device queue. §4.2

13 CHAPTER FOUR, OPERATING SYSTEMS 12 Ready Queue and Various I/O Device Queues

14 CHAPTER FOUR, OPERATING SYSTEMS 13 Process Migration A common representation for process migration is a queueing diagram. A new process is initially put in the ready queue. It waits in the ready queue until it is selected for execution or is dispatched. Once the process is allocated the CPU and is executing, one of several events could occur: Issue an I/O request and be placed in an I/O queue. Create a new subprocess and wait for its termination. Be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.

15 CHAPTER FOUR, OPERATING SYSTEMS 14 Queueing Diagram

16 CHAPTER FOUR, OPERATING SYSTEMS 15 Schedulers Scheduler select processes from scheduling queues for their migration within the system. Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue (loaded into memory for execution). Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU. Primary difference between them: the frequency of execution. §4.2.2 Select frequently (miliseconds)  must be fast Invoked very infrequently (seconds, minutes)  may be slow

17 CHAPTER FOUR, OPERATING SYSTEMS 16 Long-term scheduler The long-term scheduler controls the degree of multiprogramming (the number of processes in memory). It is important that the long-term scheduler select a good process mix of I/O-bound and CPU-bound processes to reach the best performance. If all processes are I/O bound … If all processes are CPU bound … If no long-term scheduler… (some time-sharing system such as UNIX) THINK

18 CHAPTER FOUR, OPERATING SYSTEMS 17 Medium-term scheduler Some OS may introduce an additional, intermediate level of scheduling. Key idea: sometimes it can be advantageous to remove processes from memory (and from active contention for the CPU), and thus to reduce the degree of multiprogramming………swapping. Swapping may be necessary to improve the process mix, or because a change in memory requirements has overcommitted available memory, requiring memory to be freed up.

19 CHAPTER FOUR, OPERATING SYSTEMS 18 Medium-term scheduler

20 CHAPTER FOUR, OPERATING SYSTEMS 19 Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. The context of a process is represented in the PCB of a process. When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. Context-switch time is overhead; the system does no useful work while switching. Time dependent on hardware support. §4.2.3

21 CHAPTER FOUR, OPERATING SYSTEMS 20 Process Creation Parent process creates children processes, which, in turn create other processes, forming a tree of processes. (Fig. 4.7)(Fig. 4.7) Resource sharing A subprocess may obtain its resources directly from the OS, or may be constrained to a subset of the resources of the parent process. §4.3.1 prevents any process from overloading the system by creating too many subprocesses

22 CHAPTER FOUR, OPERATING SYSTEMS 21 A Tree of Processes On a Typical UNIX System Back

23 CHAPTER FOUR, OPERATING SYSTEMS 22 Process Creation Execution possibilities Parent and children execute concurrently. Parent waits until some or all children have terminated. Address space Child is a duplicate of the parent. Child has a program loaded into it. UNIX examples Each process is identified by its process identifier. A new process is created by the fork system call. Both the parent and the child continue execution at the instruction after the fork with different returning code: 0 : child, nonzero (process id): parent execlp system call used after a fork to replace the process ’ memory space with a new program.

24 CHAPTER FOUR, OPERATING SYSTEMS 23 UNIX Example #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); }

25 CHAPTER FOUR, OPERATING SYSTEMS 24 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 ) for following reasons: Child has exceeded allocated resources. Task assigned to the child is no longer required. Parent is exiting. Operating system does not allow child to continue if its parent terminates … called cascading termination. §4.3.2

26 CHAPTER FOUR, OPERATING SYSTEMS 25 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child

27 CHAPTER FOUR, OPERATING SYSTEMS 26 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child

28 CHAPTER FOUR, OPERATING SYSTEMS 27 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child

29 CHAPTER FOUR, OPERATING SYSTEMS 28 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child

30 CHAPTER FOUR, OPERATING SYSTEMS 29 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child

31 CHAPTER FOUR, OPERATING SYSTEMS 30 #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } (pid > 0 ) (pid = 0) #include Void main(int argc, char *argv[]) {int pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid == 0) { /* child process */ execlp(“/bin/ls”,”ls”,Null); } else { /* parent process wait for the child to complete*/ wait(NULL); printf(“Child Complete”); exit(0); } Parent Child /bin/ls

32 CHAPTER FOUR, OPERATING SYSTEMS 31 Cooperating Processes Independent process cannot affect or be affected by the execution of another process. Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up: if multiple processor exists. Modularity: divide the system function into separate processes or threads. Convenience: a user may have many tasks on which to work at one time. §4.4

33 CHAPTER FOUR, OPERATING SYSTEMS 32 Producer-Consumer Problem A common paradigm for cooperating processes, producer process produces information that is consumed by a consumer process. Require a buffer that can be filled by the producer and emptied by the consumer. The producer and consumer must be synchronized, so that the consumer does not try to consume an item that has not yet been produced. unbounded-buffer places no practical limit on the size of the buffer. bounded-buffer assumes that there is a fixed buffer size.

34 CHAPTER FOUR, OPERATING SYSTEMS 33 Bounded-Buffer – Shared-Memory Solution (Fig 4.9) Shared data  #define BUFFER_SIZE 10  Typedef struct { ...  } item;  item buffer[BUFFER_SIZE];  int in = 0;  int out = 0; Solution is correct, but can only use BUFFER_SIZE-1 elements

35 CHAPTER FOUR, OPERATING SYSTEMS 34 Bounded-Buffer – Shared-Memory Solution Bounded (Circular) Buffer Producer (Producer stores data in buffer(in). The value of in is increased by 1) Consumer (Consumer reads contents of last full buffer. The value of out is incremented by 1.) in out

36 CHAPTER FOUR, OPERATING SYSTEMS 35 Bounded-Buffer – Shared-Memory Solution Producer process item nextProduced; while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; }

37 CHAPTER FOUR, OPERATING SYSTEMS 36 Bounded-Buffer – Shared-Memory Solution Consumer process item nextConsumed; while (1) { while (in == out) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; }

38 CHAPTER FOUR, OPERATING SYSTEMS 37 Interprocess Communication (IPC) Message-passing system for processes to communicate and to synchronize their actions without sharing the same address space. Useful in distributed environment. Ex: chat program IPC facility provides at least two operations: send(message) – message size fixed or variable receive(message) If P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive Implementation of communication link physical (e.g., shared memory, hardware bus, network) logical (e.g., logical properties) §4.5

39 CHAPTER FOUR, OPERATING SYSTEMS 38 Communicating processes must have a way to refer to each other, directly or indirectly. Direct communication Indirect communication §4.5.2 Naming

40 CHAPTER FOUR, OPERATING SYSTEMS 39 Direct Communication Processes must name each other explicitly: send(P, message) – send a message to process P receive(Q, message) – receive a message from process Q Properties of communication link Links are established automatically. The processes need to know only each other ’ s identity to communicate. A link is associated with exactly two processes. Between each pair there exists exactly one link. §4.5.2.1

41 CHAPTER FOUR, OPERATING SYSTEMS 40 Direct Communication A variant of symmetry in addressing is asymmetry addressing: only the sender names the recipient; the recipient is not required to name the sender. send(P, message) – send a message to process P receive(id, message) – receive a message from any process; id is set to the name the process with which communication has taken place. Both symmetry and asymmetry communication has limited modularity of the resulting process definitions. Changing the name of a process may necessitate examining all other process definition.

42 CHAPTER FOUR, OPERATING SYSTEMS 41 Indirect Communication Messages are sent to and received from mailboxes (also referred to as ports). Each mailbox has a unique id. Processes can communicate only if they share a mailbox. send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes. Each pair of processes may share several communication links. §4.5.2.2

43 CHAPTER FOUR, OPERATING SYSTEMS 42 A mailbox may be owned either by a process or by the operating system. 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 processes. Allow only one process at a time to execute a receive operation. Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was. Indirect Communication

44 CHAPTER FOUR, OPERATING SYSTEMS 43 Synchronization Message passing may be either blocking or nonblocking – also known as synchronous and asynchronous. Blocking send : The sending process is blocked until the message is received. Nonblocking send : The sending process resumes operation. Blocking receive : The receiver blocks until a message is available. Nonblocking receive : The receiver retrieves either a valid message or a null. When both the send and receive are blocking, we have a rendezvous between sender and receiver. §4.5.3

45 CHAPTER FOUR, OPERATING SYSTEMS 44 Buffering Message exchanged by communicating processes reside in a temporary queue implemented in one of three ways. 1.Zero capacity – 0 messages Sender must wait for receiver (rendezvous). 2.Bounded capacity – finite length of n messages Sender must wait if link full. 3.Unbounded capacity – infinite length Sender never waits. §4.5.4

46 CHAPTER FOUR, OPERATING SYSTEMS 45 An Example: Mach ( 略 )

47 CHAPTER FOUR, OPERATING SYSTEMS 46 Example: Windows 2000 Windows 2000 supports multiple operating environments or subsystems, with which application programs (i.e. clients) communicate via a message-passing mechanism. In Windows 2000, the message-passing between two processes that are on the same machine is called the local procedure-call facility (LPC). NT uses a port object to establish and maintain a connection between two processes.

48 CHAPTER FOUR, OPERATING SYSTEMS 47 Example: Windows 2000 Communication works as follows: The client opens a handle to the subsystem’s connection port object. The client sends a connection request. The server creates two private communication ports, and returns the handle to one of them to the client The client and server use the corresponding port handle to send messages or callbacks and to listen for replies

49 CHAPTER FOUR, OPERATING SYSTEMS 48 Example: Windows 2000 NT uses three types of message-passing techniques over a port that the client specifies when it establishes the channel: For small message, uses the port’s message queue as intermediate storage and copies the message from one process to the other. For larger message, it passes the message through a section object (shared memory). For better performance, in quick LPC, the server sets up a dedicated server thread to handle requests.

50 CHAPTER FOUR, OPERATING SYSTEMS 49 Communication in Client-Server Systems §4.6.1 A Socket is defined as an endpoint for communication. A pair of processes (or threads) communicating over a network employs a pair of sockets – one for each process. A socket is identified by an IP address concatenated with a port number.

51 CHAPTER FOUR, OPERATING SYSTEMS 50 Sockets The server waits for incoming client requests by listening to a specified port. Once a request is received, the server accepts a connection from the client socket to complete the connection. Servers implementing specific services by listening to well-known ports. Telnet server listens to port 23. Ftp server listens to port 21. Web server (http) listens to port 80. All ports below 1024 are considered well known.

52 CHAPTER FOUR, OPERATING SYSTEMS 51 Sockets When a client thread initiates a request for a connection, it is assigned an arbitrary port (> 1024) by the host computer. Example: a client on host X with IP address 146.86.5.20 wishes to establish a connection with a web server at 161.25.19.8 socket 146.86.5.20/1625 socket 161.25.19.8/80 host X (146.86.5.20) web server ( 161.25.19.8 )

53 CHAPTER FOUR, OPERATING SYSTEMS 52 Sockets The packets traveling between the hosts are delivered to the appropriate process, based on the destination port number. All connection must be unique. Therefore, if another process also on host X wished to establish another connection with the same web server, it would be assigned a port number > 1024 and ≠ 1625.

54 CHAPTER FOUR, OPERATING SYSTEMS 53 Java Sockets Java provides three different types of sockets: Connection-oriented (TCP) sockets (implemented with socket class) Connectionless (UDP) sockets (use the DatagramSocket class) MulticastSocket socket, a subclass of the DatagramSocket class, allows data to be sent to multiple recipients.

55 CHAPTER FOUR, OPERATING SYSTEMS 54 Java Sockets Example: Multithreaded time-of-day server allows clients to request the time of day from the server. When a connection is received, the server creates a new thread to serve the request. This new thread returns to the client the current time of day.

56 CHAPTER FOUR, OPERATING SYSTEMS 55 Time-of-day Server import java.net.*; import java.io.*; public class Server { public static void main(String[] args) throws IOException { Socket client = null; PrintWriter pout = null; ServerSocket sock = null; try { sock = new ServerSocket(5155); //now listen for connections while (true) { client = sock.accept(); // we have a connection pout = new PrintWriter(client.getOUtputStream(), true); // write the Date to the socket pout.println(new java.util.Date().toString()); pout.close(); client.close(); } } catch (IOException ioe) { System.err.println(ioe); } finally { if (client != null) client.close(); if (sock != null) sock.close(); } } } Creates a ServerSocket that specifies that it will listen to port 5155 Listening to the port by blocking with accept() method and wait for a client to request a connection.

57 CHAPTER FOUR, OPERATING SYSTEMS 56 Once the connection is made, the client can read from the socket using normal file I/O statements. The Client import java.net.*; import java.io.*; public class Client { public static void main(String[] args) throws IOException { InputStream in = null; BufferedReader bin = null; Socket sock = null; try { // make connection to socket sock = new Socket(“127.0.0.1”,5155); in = sock.getInputStream(); bin = new BufferedReader(new InputStreamReader(in)); String line; while ((line = bin.readLine()) != null) System.out.println(line); } catch (IOException ioe) { System.err.println(ioe); } finally { if (sock != null) sock.close(); } } } create a socket and connecting to the port the server is listening on. After it has received the time of day from the server, the client closes the socket and exit.

58 CHAPTER FOUR, OPERATING SYSTEMS 57 Higher-Level Methods of Communication Communication using sockets – although common and efficient – is considered a low- level form. Socket allow only unstructured stream of bytes to be exchanged. The client or server application need to impose a structure on the data. Two higher-level methods: Remote Procedure Calls Remote Method Invocation

59 CHAPTER FOUR, OPERATING SYSTEMS 58 Remote Procedure Call The semantics of an RPC system allows a client to invoke a procedure on a remote host as it would invoke a local procedure. Advantage: Since the RPC system manages the communication channel, so application programs can be written such that the location of a procedure is transparent. The process may be on the same computer, or on a different computer connected by a network. §4.6.2

60 CHAPTER FOUR, OPERATING SYSTEMS 59 RPC vs. IPC It is similar to the IPC mechanism and usually built on top of it. The messages exchanged for RPC are well structured and are thus no longer just packets of data. They are addressed to an RPC daemon listening to a port on the remote system, and contain in identifier of the function to execute and the parameters to pass to that function. The function is then executed as requested, and any output is sent back to the requester in a separate message.

61 CHAPTER FOUR, OPERATING SYSTEMS 60 Port A port is simply a number included at the start of a message packet. Whereas a system normally has one network address, it can have many ports within that address to differentiate the many network services it supports. If a remote process needs a service, it addresses its messages to the proper port. Example: a system allows other systems to be able to list its current user, it would have a daemon supporting such an RPC attached to a port, say 3027. Other systems may now send an RPC message to port 3027

62 CHAPTER FOUR, OPERATING SYSTEMS 61 Stub The RPC system use a stub to hide the necessary details allowing the communication to take place. A separate stub exists for each separate remote procedure. When the client invokes a remote procedure, the RPC system calls the appropriate stub, passing it the parameters provided to the remote proceudre. The stub locates the port on the server and packaging the parameters for transmitting over the network.

63 CHAPTER FOUR, OPERATING SYSTEMS 62 Stub The stub then transmits a message to the server using message passing. A similar stub on the server side receives this message and invokes the procedure on the server.

64 CHAPTER FOUR, OPERATING SYSTEMS 63 Timestamp To avoid duplicating the RPC due to network errors, each message is attached a timestamp. The server keep a history of all the timestamps of messages it has already processed. Incoming messages that have a timestamp already in the history are ignored.

65 CHAPTER FOUR, OPERATING SYSTEMS 64 Port Binding How does a client know the port numbers on the server? 1.The binding info may be predetermined, in the form of fixed port addresses. Once a program is compiled, the server cannot change the port number of the requested services. 2.Binding can be done dynamically by a rendezvous mechanism. OS provides a rendezvous daemon for matching the port numbers…overhead initially but more flexible.

66 CHAPTER FOUR, OPERATING SYSTEMS 65 Port Binding

67 CHAPTER FOUR, OPERATING SYSTEMS 66 Remote Method Invocation RMI is a Java feature similar to RPCs, which allows a thread to invoke a method on a remote object. §4.6.3 On remote JVM

68 CHAPTER FOUR, OPERATING SYSTEMS 67 RPC vs. RMI RPCs support procedural programming: only remote procedures and functions may be called. RMI is object-oriented: supports invocation of methods on remote objects. RPC’s parameters to remote procedures are ordinary data structures. RMI is possible to pass objects as parameters.

69 CHAPTER FOUR, OPERATING SYSTEMS 68 Parameter Marshalling Client-side stub is responsible for creating a parcel consisting of the name of the method to be invoked on the server and the marshalled parameters for the method. The stub then sends this parcel to the server, where the skeleton for the remote object receives it. The skeleton is responsible for unmarshalling the parameters and invoking the desired method on the server. The skeleton then marshalls the return value into a parcel and returns this parcel to the client. The stub unmarshalls the return value and passes it to the client.

70 CHAPTER FOUR, OPERATING SYSTEMS 69 Parameter Marshalling


Download ppt "CHAPTER 4 PROCESSES Operating Systems CHAPTER FOUR, OPERATING SYSTEMS 2 Processes Current-day computer systems allow multiple programs to be loaded into."

Similar presentations


Ads by Google