0% found this document useful (0 votes)
44 views

Operating Systems - ch4-F06

This document summarizes key topics about processes from Chapter 4 of an operating systems textbook. It discusses process concepts like process state and process control blocks. It also covers process scheduling with different queues, context switching, and types of schedulers. Process synchronization methods like shared memory and message passing for interprocess communication are described. Direct and indirect communication models are explained as ways for processes to exchange information.

Uploaded by

Ahmad Shdifat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Operating Systems - ch4-F06

This document summarizes key topics about processes from Chapter 4 of an operating systems textbook. It discusses process concepts like process state and process control blocks. It also covers process scheduling with different queues, context switching, and types of schedulers. Process synchronization methods like shared memory and message passing for interprocess communication are described. Direct and indirect communication models are explained as ways for processes to exchange information.

Uploaded by

Ahmad Shdifat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 41

Operating Systems

404452 Section 1 9 October 2004 Chapters 4

Chapter 4: Processes
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems

Chapter 4

Operating Systems

Process Concept
An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Textbook uses the terms job and process almost interchangeably Process a program in execution; process execution must progress in sequential fashion A process includes: program counter stack data section
Chapter 4 Operating Systems 3

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
Chapter 4 Operating Systems 4

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

Chapter 4

Operating Systems

CPU Switch From Process to Process

Chapter 4

Operating Systems

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 Device queues set of processes waiting for an I/O device Processes migrate among the various queues

Chapter 4

Operating Systems

Ready Queue And Various I/O Device Queues

Chapter 4

Operating Systems

Representation of Process Scheduling

Chapter 4

Operating Systems

Schedulers
Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU Medium-term scheduler removes partially executed (incomplete) processes in and out of memory

Chapter 4

Operating Systems

10

Addition of Medium Term Scheduling

Chapter 4

Operating Systems

11

Schedulers (Cont.)
Short-term scheduler is invoked very frequently (milliseconds) (must be fast) Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming Processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts 12 Chapter 4 Operating Systems

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 Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support

Chapter 4

Operating Systems

13

Process Creation
Parent process create children processes, which, in turn create other processes, forming a tree of processes Resource sharing Parent and children share all resources Children share subset of parents resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until children terminate

Chapter 4

Operating Systems

14

Process Creation (Cont.)


Address space Child duplicate of parent (child has the same program and data with parent). Child has a program loaded into it UNIX examples fork system call creates new process exec system call used after a fork to replace the process memory space with a new program

Chapter 4

Operating Systems

15

C Program Forking Separate Process


int main() { Pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); //replace address space with new program } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); Operating Systems }

Chapter 4

16

A tree of processes on a typical Solaris

Chapter 4

Operating Systems

17

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) Case 1: Child has exceeded allocated resources Case 2: Task assigned to child is no longer required Case 3: parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination
Chapter 4 Operating Systems 18

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 (parallel programming) Advantages of process cooperation
Information sharing (concurrent users interested in the same information). Computation speed-up Modularity Convenience (single user can issues several task in the same time)

Chapter 4

Operating Systems

19

InterProcess Communication (IPC)


Cooperating processes requires means of managing the exchange of information and data. This means (ways) are know as IPC which is a mechanism for processes to communicate and to synchronize their actions Two main ways to establish IPC: 1) Shared memory Part of the memory is shared between the cooperating processes. The cooperating processes can read/write to this shared space.

2) Message passing The cooperating processes communicate throughout exchanging messages.


Chapter 4 Operating Systems 20

Shared memory : Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size

Chapter 4

Operating Systems

21

Bounded-Buffer Shared-Memory Solution Shared data #define BUFFER_SIZE 10 Typedef struct { ... } item;
item buffer[BUFFER_SIZE]; int in = 0;// points to next free location int out = 0;// points to the first full location

Buffer is FULL if (in+1 % BUFFER_SIZE ==out) Buffer is Empty if in == out Solution is correct, but can only use BUFFER_SIZE-1 elements
Chapter 4 Operating Systems 22

Bounded-Buffer Insert() Method

while (true) { /* Produce an item */ while ( (in + 1) % BUFFER_SIZE_count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; {

Chapter 4

Operating Systems

23

Bounded Buffer Remove() Method


while (true) { while (in == out) ; // do nothing -- nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER_SIZE; return item; {

Chapter 4

Operating Systems

24

Message passing
Message system processes communicate with each other without resorting to shared variables Useful in distributed environments. IPC facility provides 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) logical (e.g., logical features: Direct/Indirect synchronous/asynchronous )

Chapter 4

Operating Systems

25

Implementation Questions
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?

Chapter 4

Operating Systems

26

Communications Models

Chapter 4

Operating Systems

27

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 A link is associated with exactly one pair of communicating processes Between each pair there exists exactly one link The link may be unidirectional, but is usually bidirectional

Disadvantage changing process identifier requires modifying all references to it.


Chapter 4 Operating Systems 28

Indirect Communication
Messages are directed and received from mailboxes (also referred to as ports) Mailbox is an object in which messages are placed into Each mailbox has a unique id Processes can communicate only if they share a mailbox 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 Link may be unidirectional or bi-directional
Chapter 4 Operating Systems 29

Indirect Communication
Operations create a new mailbox send and receive messages through mailbox destroy a mailbox Primitives are defined as: send(A, message) send a message to mailbox A receive(A, message) receive a message from mailbox A

Chapter 4

Operating Systems

30

Indirect Communication
Mailbox sharing P1, P2, and P3 share mailbox A P1, sends; P2 and P3 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.
Chapter 4 Operating Systems 31

Indirect communication (2)


Mailbox owned by a process. - The process that owns the mailbox can executes receive only. This elevates the problem of who should receive the message. - If the process who owns the mailbox terminates, the mailbox should be destroyed Mailbox owned by the OS - Created and controlled by the OS. - Only the OS can destroy the mailbox.

Chapter 4

Operating Systems

32

Synchronization
Message passing may be either blocking or non-blocking Blocking is considered 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 considered asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null
Chapter 4 Operating Systems 33

Buffering
Regardless whether the communication is direct or indirect the messages must reside in temporary queue. Queue of messages attached to the link; implemented in one of three ways 1. Zero capacity the queue has 0 length Sender must block for receiver 2. Bounded capacity finite length of n messages -If queue is not full sender send and continue If queue is full Sender must block 3. Unbounded capacity infinite length Sender never waits
Chapter 4 Operating Systems 34

Client-Server Communication
Sockets Remote Procedure Calls Remote Method Invocation (Java)

Chapter 4

Operating Systems

35

Sockets
A socket is defined as an endpoint for communication Any pair of processes wish to communicates must employ a pair of sockets. One on each side. Concatenation of IP address and port The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 Communication consists between a pair of sockets Sockets are client-server architecture, where server listen to well-known ports. Once message is received on these ports it accepts the connection from client socket.
Chapter 4 Operating Systems 36

Socket Communication

* How a process in different computer can establish a connection with the web server ? * How could another process in the samer computer establish a connection with the web server ?
Chapter 4 Operating Systems 37

Remote Procedure Calls


Remote procedure call (RPC) abstracts procedure calls between processes on networked systems. Stubs (Proxy for the remote object). It is a software that acts as an interface with the actual RPC and hides the details of real RPC communication. Each RPC on the client has a specific stub. Marshalling: the process of converting the parameters into a format the could be transmitted over the network and understood by the server. The client-side stub locates the port on the server and marshalls the parameters. The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server.

Chapter 4

Operating Systems

38

Execution of RPC
RPC steps: 1-Client invokes RPC.

2-The suitable stub on the client is called with the procedure parameters.
3-The stub locates procedure port on the server, marshalls the parameters and sends the request. 4-The server stub receives the request, unmarshalls the parameters, performs the required procedure and returns the result.

Chapter 4

Operating Systems

39

Remote Method Invocation


Remote Method Invocation (RMI) is a Java mechanism similar to RPCs. RMI allows a Java program on one machine to invoke a method on a remote object. Objects are considered remote if they are located in different (JVM).

Chapter 4

Operating Systems

40

Marshalling Parameters
Stub: Client side proxy that is called when the client invokes a remote object. Skeleton: server side proxy that is responsible for unmarshalling the parameters and calling the desired remote method.

Chapter 4

Operating Systems

41

You might also like