Chapter 3: Processes
Chapter 3: Processes

            s Process Concept
            s Process Scheduling
            s Operations on Processes
            s Cooperating Processes
            s Interprocess Communication
            s Communication in Client-Server Systems




Operating System Concepts                  3.2         Silberschatz, Galvin and Gagne
Process Concept
            s An operating system executes a variety of programs:
                  q   Batch system – jobs
                  q   Time-shared systems – user programs or tasks
            s Textbook uses the terms job and process almost interchangeably
            s Process – a program in execution; process execution must progress in
                sequential fashion
            s A process includes:
                  q   program counter which represents current activity
                  q   Stack which holds temporary data such as function parameters,
                      local variables and return addresses.
                  q   data section which contains global variables
                  q   Heap which contains memory that is dynamically allocated during
                      process runtime.
                  q   Text includes the application's code, might be shared by a number of
                      processes?
                  q   The process's address space.
Operating System Concepts                        3.3                      Silberschatz, Galvin and Gagne
Process in Memory




Operating System Concepts          3.4          Silberschatz, Galvin and Gagne
Process State

            s As a process executes, it changes state

                  q   new: The process is being created

                  q   running: Instructions are being executed

                  q   waiting: The process is waiting for some event to occur

                  q   ready: The process is waiting to be assigned to a
                      processor

                  q   terminated: The process has finished execution




Operating System Concepts                    3.5                  Silberschatz, Galvin and Gagne
Diagram of Process State




Operating System Concepts             3.6        Silberschatz, Galvin and Gagne
Process Control Block (PCB)

            Information associated with each process
            s Process state
            s Program counter indicates the address of next instruction.
            s CPU registers
            s CPU scheduling information includes process priority and pointers
                to scheduling queues.
            s Memory-management information includes value of limit and base
                registers
            s Accounting information includes amount of CPU time used, time
                limits etc.
            s I/O status information includes the list of I/O devices allocated to
                processes, list of open files




Operating System Concepts                       3.7                 Silberschatz, Galvin and Gagne
Process Control Block (PCB)




Operating System Concepts         3.8       Silberschatz, Galvin and Gagne
OS Data                  PCB                     Process
   Structures                                       Address
                                                    Space
             RAM                                                      CPU

                             Kernel   User
                                                                       PSW

                  State                            text
                                                                         IR
                  Memory .
                  Files
                  Accounting                                            PC
                  Priority                         data
                  User                                                  SP
                  CPU register
                  storage                          heap             General
                                                                    Purpose
                                                                    Registers
                                               stack


                                                              9
Operating System Concepts                    3.9                  Silberschatz, Galvin and Gagne
CPU Switch From Process to
                               Process




Operating System Concepts        3.10      Silberschatz, Galvin and Gagne
Process Scheduling Queues
            s Job queue – set of all processes in the system

            s Ready queue

                  q   set of all processes residing in main memory, ready and
                      waiting to execute.

                  q   It is stored as a linked list. It contains pointers to the first
                      and final PCB’s.

                  q   Each PCB includes a pointer field that points to the next
                      PCB in the ready queue.

            s Device queues – set of processes waiting for an I/O device

            s Processes migrate among the various queues

Operating System Concepts                       3.11                    Silberschatz, Galvin and Gagne
Queues




Operating System Concepts   3.12     Silberschatz, Galvin and Gagne
Representation of Process
                                  Scheduling




Operating System Concepts             3.13       Silberschatz, Galvin and Gagne
Schedulers

            s Long-term scheduler (or job scheduler) – selects
                which processes should be brought into the ready queue
            s Short-term scheduler (or CPU scheduler) – selects
                which process should be executed next and allocates
                CPU
            s Medium term Scheduler             (Swaper)




Operating System Concepts                    3.14                     Silberschatz, Galvin and Gagne
Addition of Medium Term Scheduling




Operating System Concepts   3.15    Silberschatz, Galvin and Gagne
Schedulers (Cont.)

            s Short-term scheduler is invoked very frequently (milliseconds) ⇒
                (must be fast)
            s Long-term scheduler is invoked very infrequently (seconds, minutes)
                ⇒ (may be slow)
            s The long-term scheduler controls the degree of multiprogramming
            s Processes can be described as either:
                  q   I/O-bound process – spends more time doing I/O than
                      computations, many short CPU bursts
                  q   CPU-bound process – spends more time doing computations;
                      few very long CPU bursts
            s If all processes are I/O bound,
                  q   The ready queue will almost always be empty
            s If all processes are CPU bound,
                  q   The I/O waiting queue will almost always be empty, devices will
                      go unused
                  q   System will again be unbalanced
Operating System Concepts                       3.16                    Silberschatz, Galvin and Gagne
Context Switch

            s 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

            s Context-switch time is overhead; the system does

                no useful work while switching

            s Time dependent on hardware support

            s Part of OS responsible for switching the processor

                among the processes is called Dispatcher

Operating System Concepts             3.17                 Silberschatz, Galvin and Gagne
Two-state process model

                                                     Processor
                                Queue
                       Enter                 Dispatch        Exit




                                        Pause


        Dispatcher is now redefined:
                    • Moves processes to the waiting queue
                    • Remove completed/aborted processes
                    • Select the next process to run

                                                                18
Operating System Concepts                 3.18                      Silberschatz, Galvin and Gagne
How process state changes1
                            Ready           Ready           Ready

                             a := 1         a := 1         a := 1
                              b := a + 1      read a file     b := a + 1
                              c := b + 1      b := a + 1      c := b + 1
                              read a file     c := b + 1      a := b - c
                              a := b - c      a := b - c      c := c * b
                              c := c * b      c := c * b      b := 0
                              b := 0          b := 0          c := 0




                                                                   19
Operating System Concepts                       3.19                Silberschatz, Galvin and Gagne
How process state changes2
                            Running              Ready           Ready

                             a := 1              a := 1         a := 1
                              b a aa 1 1
                                :=:=:= 1
                                     +             read a file     b := a + 1
                              b := a + 1
                              c :=bb:= a + 1
                                     +1            b := a + 1      c := b + 1
                                c :=abfile1
                                        +
                              read := b + 1        c := b + 1      a := b - c
                               c a file
                              a read - ca file
                                := b               a := b - c      c := c * b
                                a readb c
                                  := * -
                                     b
                              c :=ac:= b - c      Timeout
                                                   c := c * b      b := 0
                              b c c0 c c b b
                                :=:=:= * *         b := 0          c := 0
                                b := 0
                                  b := 0




                                                                        20
Operating System Concepts                            3.20                Silberschatz, Galvin and Gagne
How process state changes3
                            Ready           Running           Ready

                              a := 1         a := 1           a := 1
                              b := a + 1      read a1file
                                                a :=            b := a + 1
                              c := b + 1      read + 1
                                              b := a a file     c := b + 1
                             read a file     c b := a + 1
                                                := b + 1        a := b - c
                              a := b - c      a := b - +
                                                c := b c 1      c := c * b
                              c := c * b         I/O
                                              c a := * b c
                                                := c b -        b := 0
                              b := 0          b c := c * b
                                                := 0            c := 0
                                                b := 0




                                                                     21
Operating System Concepts                       3.21                  Silberschatz, Galvin and Gagne
How process state changes4
                            Ready           Blocked         Running

                              a := 1          a := 1         a := 1
                              b := a + 1     read a file     ba :=a:= 1
                                                                :=a 1 1
                                                                     +
                              c := b + 1      b := a + 1      b := a + 1
                                                              c :=bb:= a + 1
                                                                     +1
                             read a file     c := b + 1        c := b c 1
                                                                       +
                                                              a := b - b + 1
                                                               c := - c
                              a := b - c      a := b - c      c a ac:= b - c
                                                                :=:= * b
                                                                     b
                              c := c * b     Timeout
                                              c := c * b      b c c0 c c b b
                                                                :=:=:= * *
                              b := 0          b := 0          c b b0:= 0
                                                                :=:= 0
                                                                c := 0
                                                                  c := 0




                                                                   22
Operating System Concepts                       3.22                  Silberschatz, Galvin and Gagne
How process state changes5
                            Running         Blocked         Ready

                              a := 1          a := 1          a := 1
                              b := a + 1     read a file     b := a + 1
                              c := b + 1      b := a + 1      c := b + 1
                             read a file     c := b + 1     a := b - c
                              a := b - c      a := b - c      c := c * b
                              c := c * b         I/O
                                              c := c * b      b := 0
                              b := 0          b := 0          c := 0




                                                                   23
Operating System Concepts                       3.23                Silberschatz, Galvin and Gagne
How process state changes6
                            Blocked         Blocked            Running
                                                            The Next Process to Run
                                                            cannot be simply selected
                              a := 1          a := 1              a := 1
                              b := a + 1     read a file   from the front1
                                                                  b := a +
                              c := b + 1      b := a + 1        c := b + 1
                             read a file     c := b + 1       a := b - c
                              a := b - c      a := b - c        c := c * b
                              c := c * b      c := c * b        b := 0
                              b := 0          b := 0            c := 0




                                                                     24
Operating System Concepts                       3.24                  Silberschatz, Galvin and Gagne
How process state changes7
                            Blocked            Blocked            Running

                              a := 1             a := 1             a := 1
                              b := a + 1       read a file         b a := 1 1
                                                                      := a +
                              c := b + 1         b := a + 1           b := a + 1
                                                                    c := b + 1
                             read a file        c := b + 1       a c := b c 1
                                                                      := b - +
                              a := b - c         a := b - c         c a := * b c
                                                                      := c b -
                              c :=Suppose the Green process finishesbI/O0 c * b
                                   c*b           c := c * b         c :=
                                                                      :=
                              b := 0             b := 0               b := 0
                                                                    c := 0
                                                                      c := 0




                                                                         25
Operating System Concepts                          3.25                     Silberschatz, Galvin and Gagne
How process state changes8
                            Blocked         Ready           Running

                              a := 1          a := 1          a := 1
                              b := a + 1      read a file     b a aa:= 1
                                                                :=:= 1 1
                                                                     +
                              c := b + 1     b := a + 1        b := a + 1
                                                              c :=bb:= a + 1
                                                                     +1
                             read a file     c := b + 1        c := b c 1
                                                                     - +
                                                             a :=cb:= b + 1
                              a := b - c      a := b - c      c a ac:= b c c
                                                                :=:= * b -
                                                                     b-
                              c := c * b     Timeout
                                              c := c * b      c := c * b
                                                              b :=c0 c * b
                                                                    :=
                              b := 0          b := 0          c b b0:= 0
                                                                :=:= 0
                                                               := 0
                                                                c
                                                                  c := 0




                                                                   26
Operating System Concepts                       3.26                  Silberschatz, Galvin and Gagne
How process state changes9
                            Blocked         Running             Ready

                              a := 1          a := 1              a := 1
                              b := a + 1      read a1file
                                                a :=              b := a + 1
                              c := b + 1        read+ 1file
                                                  a :=a
                                             b :=read 1 file
                                                   a a            c := b + 1
                             read a file       b := a + 1
                                              c :=bb + a1         a := b - c
                              a := b - c      c :=:= c + 1
                                                     b+1
                                              a :=cb - b +        c := c * b
                              c := c * b     Timeout- c 1
                                                    :=
                                              c a ac:= b - c
                                                :=:= * b
                                                     b            b := 0
                                               := c * b
                              b := 0          b c c0 c * b
                                                :=               c := 0
                                                b :=:=
                                                     0
                                                  b := 0




                                                                       27
Operating System Concepts                       3.27                    Silberschatz, Galvin and Gagne
Process Creation
            s Reasons to create a process
                           Submit a new batch job/Start program
                           User logs on to the system
                           OS creates on behalf of a user (printing)
                           Spawned by existing process
            s Parent process create children processes, which, in turn create other
                processes, forming a tree of processes
            s Resource sharing
                  q   Parent and children share all resources
                  q   Children share subset of parent’s resources
                  q   Parent and child share no resources
            s Execution
                  q   Parent and children execute concurrently
                  q   Parent waits until children terminate

Operating System Concepts                          3.28                 Silberschatz, Galvin and Gagne
Process Creation (Cont.)

            s Address space
                  q   Child duplicate of parent
                  q   Child has a program loaded into it
            s UNIX examples
                  q   fork system call creates new process
                  q   exec system call used after a fork to replace the
                      process’ memory space with a new program




Operating System Concepts                 3.29               Silberschatz, Galvin and Gagne
Process Creation




Operating System Concepts         3.30         Silberschatz, Galvin and Gagne
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);
                               }
                               else { /* parent process */
                                     /* parent will wait for the child to
                               complete */
                                     wait (NULL);
                                     printf ("Child Complete");
                                     exit(0);
                               }
                            }


Operating System Concepts                 3.31                   Silberschatz, Galvin and Gagne
The fork() system call

            At the end of the system call there is a new process
               waiting to run once the scheduler chooses it
            s A new data structure is allocated
            s The new process is called the child process.
            s The existing process is called the parent process.
            s The parent gets the child’s pid returned to it.
            s The child gets 0 returned to it.
            s Both parent and child execute at the same point
                after fork() returns


                                                        32
Operating System Concepts              3.32              Silberschatz, Galvin and Gagne
Unix Process Control

                      The fork syscall
                      returns a zero to the
                      child and the child
                      process ID to the
      int pid;
      int status = 0; parent                    Parent uses wait to
      if (pid = fork()) {
                                                sleepFork creates an
                                                      until the
             /* parent */                       childexact copy of the
                                                      exits; wait
             ……                                 returns child pid
                                                     parent process
             pid = wait(&status);               and status.
      } else {
             /* child */                         Wait variants
             ……                                  allow wait on a
             exit(status);                       specific child, or
      }                                       Child process of
                                                 notification
                                              passes statusother
                                                 stops and back
                                              to parent on exit,
                                                 signals
                                              to report
                                              success/failure
                                                         33
Operating System Concepts            3.33                 Silberschatz, Galvin and Gagne
Process Termination
            s Batch job issues Halt instruction
            s User logs off
            s Process executes a service request to terminate
            s Parent terminates so child processes terminate
            s Operating system intervention
                  q   such as when deadlock occurs
            s Error and fault conditions
                  q   E.g. memory unavailable, protection error, arithmetic error, I/O
                      failure, invalid instruction




                                                                        34
Operating System Concepts                        3.34                     Silberschatz, Galvin and Gagne
Process Termination

            s Process executes last statement and asks the operating system to
                delete it (exit)
                  q   Output data from child to parent (via wait)
                  q   Process’ resources are deallocated by operating system
            s Parent may terminate execution of children processes (abort)
                  q   Child has exceeded allocated resources
                  q   Task assigned to child is no longer required
                  q   If parent is exiting
                           Some operating system do not allow child to continue if its
                            parent terminates
                             –   All children terminated - cascading termination




Operating System Concepts                            3.35                    Silberschatz, Galvin and Gagne
Inter process Communication

                 Processes executing concurrently in the operating
                 system may be either independent processes or
                 cooperating processes.


            s Independent process cannot affect or be affected by

                 the execution of another process

            s Cooperating process can affect or be affected by the

                 execution of another process




Operating System Concepts                3.36           Silberschatz, Galvin and Gagne
Advantages of Process Cooperation

            s Information sharing: Allow concurrent access to
                 same piece of information that several users may be
                 interested in it.
            s Computation speed-up: break a task to subtasks,
                 each of which will be executing in parallel with the
                 others. (Should be multiple processing elements such
                 as CPUs)
            s Modularity:      divided the system functions into
                 separate processes or threads.
            s Convenience: for user, user may work on many
                 tasks at the same time.


Operating System Concepts              3.37             Silberschatz, Galvin and Gagne
MODELS OF IPC

                    Cooperating processes require an inter
                    process communication mechanism that
                    will allow them to exchange data and
                    information.
            2.      Shared Memory
            3.      Message Passing




Operating System Concepts             3.38        Silberschatz, Galvin and Gagne
SHARED MEMORY


            1. Region of memory that is shared by
                    cooperating           processes                 is
                    established.
            2. Processes         can then exchange
                    information by reading and writing
                    data to shared region



Operating System Concepts          3.39               Silberschatz, Galvin and Gagne
MESSAGE PASSING


                    Communication takes place by
                    means of messages exchanged
                    between the cooperating processes.




Operating System Concepts         3.40         Silberschatz, Galvin and Gagne
Communications Models




Operating System Concepts            3.41      Silberschatz, Galvin and Gagne
Advantages & Disadvantages of Message
                  Passing & Shared Memory

       1.      Message passing is useful for exchanging
               smaller amounts of data
       2.      Message Passing is easier to implement than
               shared memory for IPC
       3.      Shared Memory allows maximum speed and
               convenience as it can be done at memory
               speeds within a computer
       4.      Shared memory is faster than message
               passing as message passing is implemented
               using system calls.
Operating System Concepts        3.42           Silberschatz, Galvin and Gagne
Contd….

       1. Message passing requires the more
               time consuming         task   of          kernel
               intervention.
       2. Shared          memory system calls are
               required only to establish shared
               memory regions, no assistance from the
               kernel is required.



Operating System Concepts      3.43               Silberschatz, Galvin and Gagne
Producer-Consumer Problem
            s Paradigm for cooperating processes, producer process
                produces information that is consumed by a consumer
                process
                  q   A compiler may produce assembly code, which is consumed
                      by an assembler. The assembler, in turn, may produce object
                      modules, which are consumed by the loader
            s A buffer of items that can be filled by the producer and emptied
                by the consumer. should be available
            s A producer can produce one item while the consumer is
                consuming another item.
            s The producer and consumer must be synchronized
                  q   the consumer does not try to consume an item that has not
                      yet been produced.
                  q   the consumer must wait until an item is produced
Operating System Concepts                    3.44                  Silberschatz, Galvin and Gagne
Producer-Consumer Problem

            s unbounded-buffer places no practical limit on the size of the

                buffer

                  q   the consumer may have to wait for new items, but

                  q   the producer can always produce new items

            s bounded-buffer assumes that there is a fixed buffer size

                  q   the consumer must wait if the buffer is empty, and

                  q   the producer must wait if the buffer is full.


Operating System Concepts                     3.45                    Silberschatz, Galvin and Gagne
Bounded-Buffer – Shared-Memory
                                Solution

            s   Shared data
                            #define BUFFER_SIZE 10
                            Typedef struct {
                              ...
                            } item;


                            item buffer[BUFFER_SIZE];
                            int in = 0; % in: the next free position in the buffer
                            int out = 0; % out: the first full position in the buffer
            s   The buffer is empty when in == out ;
            s   The buffer is full when ((in + 1) % BUFFERSIZE) == out
            s   Solution is correct, but can only use BUFFER_SIZE-1 elements



Operating System Concepts                        3.46                     Silberschatz, Galvin and Gagne
Bounded-Buffer – Insert() Method

         The producer process has a local variable nextproduced in which
         the new item to be produced is stored:
    while (true) {
         /* Produce an item */
       while (((in = (in + 1) % BUFFER SIZE
        count) == out)
              ;   /* do nothing -- no free
         buffers */
                     buffer[in] = item;
                     in = (in + 1) % BUFFER SIZE;
                   {
Operating System Concepts            3.47               Silberschatz, Galvin and Gagne
Bounded Buffer – Remove() Method

         The consumer process has a local variable nextconsumed in which the
         item to be consumed is stored:

                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;
                      {
Operating System Concepts                3.48                  Silberschatz, Galvin and Gagne
Message Passing
            s Mechanism for processes to communicate and to synchronize their
                actions
            s Message system – processes communicate with each other without
                resorting to shared variables
            s IPC facility provides two operations:
                  q   send(message) – message size fixed or variable
                  q   receive(message)
            s If P and Q wish to communicate, they need to:
                  q   establish a communication link between them
                  q   exchange messages via send/receive
            s Implementation of communication link
                  q   physical (e.g., shared memory, hardware bus)
                  q   logical (e.g., logical properties) e.g. send(), receive()




Operating System Concepts                          3.49                      Silberschatz, Galvin and Gagne
Implementation Questions

            s How are links established?
            s Can a link be associated with more than two processes?
            s How many links can there be between every pair of communicating
                processes?
            s What is the capacity of a link?
            s Is the size of a message that the link can accommodate fixed or
                variable?
            s Is a link unidirectional or bi-directional?




Operating System Concepts                       3.50                Silberschatz, Galvin and Gagne
Methods for logical implementation of link


            1. Direct or Indirect Communication


            2. Synchronous and Asynchronous

                Communication

            3. Automatic or explicit Buffering




Operating System Concepts         3.51            Silberschatz, Galvin and Gagne
Direct Communication

            s Processes must name each other explicitly:
                  q   send (P, message) – send a message to process P
                  q   receive(Q, message) – receive a message from process Q
            s Properties of communication link
                  q   Links are established automatically because the processes
                      need to know only the identities to communicate.
                  q   A link is associated with exactly one pair of communicating
                      processes
                  q   Between each pair there exists exactly one link
                  q   The link may be unidirectional, but is usually bi-directional




Operating System Concepts                         3.52                     Silberschatz, Galvin and Gagne
Indirect Communication

            s Messages are directed and received from mailboxes (also
                referred to as ports)
                  q   Each mailbox has a unique id
                  q   Processes can communicate only if they share a mailbox
            s Properties of communication link
                  q   Link established only if processes share a common mailbox
                  q   A link may be associated with many processes
                  q   Each pair of processes may share several communication
                      links
                  q   Link may be unidirectional or bi-directional




Operating System Concepts                        3.53                 Silberschatz, Galvin and Gagne
Indirect Communication

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




Operating System Concepts                     3.54                Silberschatz, Galvin and Gagne
Indirect Communication

            s Mailbox sharing
                  q   P1, P2, and P3 share mailbox A
                  q   P1, sends; P2 and P3 receive
                  q   Who gets the message?
            s Solutions
                  q   Allow a link to be associated with at most two processes
                  q   Allow only one process at a time to execute a receive operation
                  q   Allow the system to select arbitrarily the receiver. Sender is
                      notified who the receiver was.




Operating System Concepts                        3.55                     Silberschatz, Galvin and Gagne
Indirect Communication

            s If the mailbox is owned by a process (that is, the mailbox is
                part of the address space of the process),
                  q   then we distinguish between the owner (who can only receive
                      messages through this mailbox) and the user (who can only
                      send messages to the mailbox).
                  q   Since each mailbox has a unique owner, there can be
                        no     confusion about who should receive a message sent to
                            this mailbox.
                  q   When a process that owns a mailbox terminates, the mailbox
                      disappears.
                  q   Any process that subsequently sends a message to this
                      mailbox must be notified that the mailbox no longer exists.


Operating System Concepts                         3.56                   Silberschatz, Galvin and Gagne
Indirect Communication

            s If a mailbox owned by the operating system is
                independent and is not attached to any particular
                process:
                  q   The operating system then must provide a mechanism
                      that allows a process to do the following:
                        Create   a new mailbox.
                        Send   and receive messages through the mailbox.
                        Delete   a mailbox
                  q   Note: the
                              ownership and receive privilege
                      may be passed to other processes
                      through appropriate system calls.

Operating System Concepts                     3.57                 Silberschatz, Galvin and Gagne
Synchronization

            s    Message passing may be either blocking or non-blocking
            s    Blocking is considered synchronous
                  q    Blocking send has the sender block until the message is
                       received
                  q    Blocking receive has the receiver block until a message is
                       available
            s    Non-blocking is considered asynchronous
                  q    Non-blocking send has the sender send the message and
                       continue
                  q    Non-blocking receive has the receiver receive a valid
                       message or null




Operating System Concepts                      3.58                    Silberschatz, Galvin and Gagne
Buffering

            s Queue of messages attached to the link; 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




Operating System Concepts               3.59                Silberschatz, Galvin and Gagne
Client-Server Communication

            s Sockets
            s Remote Procedure Calls
            s Remote Method Invocation (Java)




Operating System Concepts                 3.60   Silberschatz, Galvin and Gagne
Sockets

            s A socket is defined as an endpoint for communication
            s Concatenation of IP address and port
            s The socket 161.25.19.8:1625 refers to port 1625 on host
                161.25.19.8
            s Communication consists between a pair of sockets




Operating System Concepts                   3.61                     Silberschatz, Galvin and Gagne
Socket Communication




Operating System Concepts           3.62      Silberschatz, Galvin and Gagne
Remote Procedure Calls

     s Remote procedure call (RPC) abstracts procedure calls between processes on
          networked systems.
     s Stubs – client-side proxy for the actual procedure on the server.
     s The client-side stub locates the server and marshalls the parameters.
     s The server-side stub receives this message, unpacks the marshalled
          parameters, and performs the procedure on the server.
     s A stub is a small program routine that substitutes for a longer program,
          possibly to be loaded later or that is located remotely. For example, a program
          that uses Remote Procedure Calls ( RPC ) is compiled with stubs that
          substitute for the program that provides a requested procedure. The stub
          accepts the request and then forwards it (through another program) to the
          remote procedure. When that procedure has completed its service, it returns
          the results or other status to the stub which passes it back to the program that
          made the request.




Operating System Concepts                    3.63                     Silberschatz, Galvin and Gagne
Execution of RPC




Operating System Concepts         3.64         Silberschatz, Galvin and Gagne
End of Chapter 3

More Related Content

PPT
CPU Scheduling
PPT
PPT
Process scheduling : operating system ( Btech cse )
PPTX
Scheduling Algorithms-R.D.Sivakumar
PPTX
Chapter4
PPTX
Scheduling algo(by HJ)
PPT
5.CPU Scheduling
PPT
Memory : operating system ( Btech cse )
CPU Scheduling
Process scheduling : operating system ( Btech cse )
Scheduling Algorithms-R.D.Sivakumar
Chapter4
Scheduling algo(by HJ)
5.CPU Scheduling
Memory : operating system ( Btech cse )

What's hot (20)

PPT
Operating System 5
PPT
Process synchonization : operating system ( Btech cse )
PPT
Cpu scheduling (1)
PDF
cpu scheduling by shivam singh
PDF
Process
PPTX
Process scheduling in Light weight weight and Heavy weight processes.
PPT
Cpu scheduling(suresh)
PDF
CPU scheduling ppt file
PDF
Scheduling
PPT
Process management in os
PPTX
CPU Sheduling
PPT
Ch6 CPU Scheduling galvin
PPT
Cpu Scheduling Galvin
PPT
Deadlock : operating system ( BTECH CSE )
PPTX
CPU Scheduling
PPT
Scheduling algorithm (chammu)
PPTX
scheduling algorithm
PPTX
Scheduling algorithms
Operating System 5
Process synchonization : operating system ( Btech cse )
Cpu scheduling (1)
cpu scheduling by shivam singh
Process
Process scheduling in Light weight weight and Heavy weight processes.
Cpu scheduling(suresh)
CPU scheduling ppt file
Scheduling
Process management in os
CPU Sheduling
Ch6 CPU Scheduling galvin
Cpu Scheduling Galvin
Deadlock : operating system ( BTECH CSE )
CPU Scheduling
Scheduling algorithm (chammu)
scheduling algorithm
Scheduling algorithms
Ad

Viewers also liked (17)

PPTX
Process in operating system
PDF
PPT
PPSX
Process scheduling
PPTX
Operating system - Process and its concepts
PPTX
Windows process-scheduling
PPTX
Operating Systems: Process Scheduling
PPTX
Operating Systems: Processor Management
PDF
Process Scheduling
PPTX
Insider operating system
PDF
3 process management
PPT
Processes Control Block (Operating System)
PDF
5 Process Scheduling
PPT
scheduling
PPTX
Operating system overview concepts ppt
Process in operating system
Process scheduling
Operating system - Process and its concepts
Windows process-scheduling
Operating Systems: Process Scheduling
Operating Systems: Processor Management
Process Scheduling
Insider operating system
3 process management
Processes Control Block (Operating System)
5 Process Scheduling
scheduling
Operating system overview concepts ppt
Ad

Similar to Chapter03 (20)

PPT
Chapter 3
PPT
OS-operating systems- ch03
PPTX
ch3-lect7.pptx
PDF
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
PPT
Template 1 ch3
PDF
Ch3 processes
PDF
Ch3OperSys
PDF
OperatingSystemChp3
PPT
Module-2 presentation.ppt of embedded system
PPT
ch3.ppt
PDF
Processes, Process Control Block, Process Scheduling.pdf
PPTX
Operating systems Week 3 Processes 01-10-2018.pptx
PPT
ch3_smu.ppt
PPT
3.Process Management
PPT
Chapter 3: Processes
PPT
OS UNIT2.ppt
PPT
Unit 2 chapter notes for the student1-1.ppt
PPTX
ch3.pptx
PPTX
Chapter 3 Processes (1)Operating systems.pptx
PDF
3 processes
Chapter 3
OS-operating systems- ch03
ch3-lect7.pptx
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
Template 1 ch3
Ch3 processes
Ch3OperSys
OperatingSystemChp3
Module-2 presentation.ppt of embedded system
ch3.ppt
Processes, Process Control Block, Process Scheduling.pdf
Operating systems Week 3 Processes 01-10-2018.pptx
ch3_smu.ppt
3.Process Management
Chapter 3: Processes
OS UNIT2.ppt
Unit 2 chapter notes for the student1-1.ppt
ch3.pptx
Chapter 3 Processes (1)Operating systems.pptx
3 processes

Recently uploaded (20)

PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Five Habits of High-Impact Board Members
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
The various Industrial Revolutions .pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPT
What is a Computer? Input Devices /output devices
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Zenith AI: Advanced Artificial Intelligence
Module 1.ppt Iot fundamentals and Architecture
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Getting started with AI Agents and Multi-Agent Systems
Five Habits of High-Impact Board Members
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Improvisation in detection of pomegranate leaf disease using transfer learni...
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Consumable AI The What, Why & How for Small Teams.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
The various Industrial Revolutions .pptx
Chapter 5: Probability Theory and Statistics
Flame analysis and combustion estimation using large language and vision assi...
sustainability-14-14877-v2.pddhzftheheeeee
What is a Computer? Input Devices /output devices
A review of recent deep learning applications in wood surface defect identifi...
Zenith AI: Advanced Artificial Intelligence

Chapter03

  • 2. Chapter 3: Processes s Process Concept s Process Scheduling s Operations on Processes s Cooperating Processes s Interprocess Communication s Communication in Client-Server Systems Operating System Concepts 3.2 Silberschatz, Galvin and Gagne
  • 3. Process Concept s An operating system executes a variety of programs: q Batch system – jobs q Time-shared systems – user programs or tasks s Textbook uses the terms job and process almost interchangeably s Process – a program in execution; process execution must progress in sequential fashion s A process includes: q program counter which represents current activity q Stack which holds temporary data such as function parameters, local variables and return addresses. q data section which contains global variables q Heap which contains memory that is dynamically allocated during process runtime. q Text includes the application's code, might be shared by a number of processes? q The process's address space. Operating System Concepts 3.3 Silberschatz, Galvin and Gagne
  • 4. Process in Memory Operating System Concepts 3.4 Silberschatz, Galvin and Gagne
  • 5. Process State s As a process executes, it changes state q new: The process is being created q running: Instructions are being executed q waiting: The process is waiting for some event to occur q ready: The process is waiting to be assigned to a processor q terminated: The process has finished execution Operating System Concepts 3.5 Silberschatz, Galvin and Gagne
  • 6. Diagram of Process State Operating System Concepts 3.6 Silberschatz, Galvin and Gagne
  • 7. Process Control Block (PCB) Information associated with each process s Process state s Program counter indicates the address of next instruction. s CPU registers s CPU scheduling information includes process priority and pointers to scheduling queues. s Memory-management information includes value of limit and base registers s Accounting information includes amount of CPU time used, time limits etc. s I/O status information includes the list of I/O devices allocated to processes, list of open files Operating System Concepts 3.7 Silberschatz, Galvin and Gagne
  • 8. Process Control Block (PCB) Operating System Concepts 3.8 Silberschatz, Galvin and Gagne
  • 9. OS Data PCB Process Structures Address Space RAM CPU Kernel User PSW State text IR Memory . Files Accounting PC Priority data User SP CPU register storage heap General Purpose Registers stack 9 Operating System Concepts 3.9 Silberschatz, Galvin and Gagne
  • 10. CPU Switch From Process to Process Operating System Concepts 3.10 Silberschatz, Galvin and Gagne
  • 11. Process Scheduling Queues s Job queue – set of all processes in the system s Ready queue q set of all processes residing in main memory, ready and waiting to execute. q It is stored as a linked list. It contains pointers to the first and final PCB’s. q Each PCB includes a pointer field that points to the next PCB in the ready queue. s Device queues – set of processes waiting for an I/O device s Processes migrate among the various queues Operating System Concepts 3.11 Silberschatz, Galvin and Gagne
  • 12. Queues Operating System Concepts 3.12 Silberschatz, Galvin and Gagne
  • 13. Representation of Process Scheduling Operating System Concepts 3.13 Silberschatz, Galvin and Gagne
  • 14. Schedulers s Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue s Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU s Medium term Scheduler (Swaper) Operating System Concepts 3.14 Silberschatz, Galvin and Gagne
  • 15. Addition of Medium Term Scheduling Operating System Concepts 3.15 Silberschatz, Galvin and Gagne
  • 16. Schedulers (Cont.) s Short-term scheduler is invoked very frequently (milliseconds) ⇒ (must be fast) s Long-term scheduler is invoked very infrequently (seconds, minutes) ⇒ (may be slow) s The long-term scheduler controls the degree of multiprogramming s Processes can be described as either: q I/O-bound process – spends more time doing I/O than computations, many short CPU bursts q CPU-bound process – spends more time doing computations; few very long CPU bursts s If all processes are I/O bound, q The ready queue will almost always be empty s If all processes are CPU bound, q The I/O waiting queue will almost always be empty, devices will go unused q System will again be unbalanced Operating System Concepts 3.16 Silberschatz, Galvin and Gagne
  • 17. Context Switch s 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 s Context-switch time is overhead; the system does no useful work while switching s Time dependent on hardware support s Part of OS responsible for switching the processor among the processes is called Dispatcher Operating System Concepts 3.17 Silberschatz, Galvin and Gagne
  • 18. Two-state process model Processor Queue Enter Dispatch Exit Pause Dispatcher is now redefined: • Moves processes to the waiting queue • Remove completed/aborted processes • Select the next process to run 18 Operating System Concepts 3.18 Silberschatz, Galvin and Gagne
  • 19. How process state changes1 Ready Ready Ready  a := 1  a := 1  a := 1 b := a + 1 read a file b := a + 1 c := b + 1 b := a + 1 c := b + 1 read a file c := b + 1 a := b - c a := b - c a := b - c c := c * b c := c * b c := c * b b := 0 b := 0 b := 0 c := 0 19 Operating System Concepts 3.19 Silberschatz, Galvin and Gagne
  • 20. How process state changes2 Running Ready Ready  a := 1  a := 1  a := 1 b a aa 1 1 :=:=:= 1 + read a file b := a + 1  b := a + 1 c :=bb:= a + 1 +1 b := a + 1 c := b + 1 c :=abfile1 + read := b + 1 c := b + 1 a := b - c  c a file a read - ca file := b a := b - c c := c * b a readb c := * - b c :=ac:= b - c Timeout c := c * b b := 0 b c c0 c c b b :=:=:= * * b := 0 c := 0 b := 0 b := 0 20 Operating System Concepts 3.20 Silberschatz, Galvin and Gagne
  • 21. How process state changes3 Ready Running Ready a := 1  a := 1  a := 1 b := a + 1 read a1file a := b := a + 1 c := b + 1  read + 1 b := a a file c := b + 1  read a file c b := a + 1 := b + 1 a := b - c a := b - c a := b - + c := b c 1 c := c * b c := c * b I/O c a := * b c := c b - b := 0 b := 0 b c := c * b := 0 c := 0 b := 0 21 Operating System Concepts 3.21 Silberschatz, Galvin and Gagne
  • 22. How process state changes4 Ready Blocked Running a := 1 a := 1  a := 1 b := a + 1  read a file ba :=a:= 1 :=a 1 1 + c := b + 1 b := a + 1  b := a + 1 c :=bb:= a + 1 +1  read a file c := b + 1 c := b c 1 + a := b - b + 1  c := - c a := b - c a := b - c c a ac:= b - c :=:= * b b c := c * b Timeout c := c * b b c c0 c c b b :=:=:= * * b := 0 b := 0 c b b0:= 0 :=:= 0 c := 0 c := 0 22 Operating System Concepts 3.22 Silberschatz, Galvin and Gagne
  • 23. How process state changes5 Running Blocked Ready a := 1 a := 1 a := 1 b := a + 1  read a file b := a + 1 c := b + 1 b := a + 1 c := b + 1  read a file c := b + 1  a := b - c a := b - c a := b - c c := c * b c := c * b I/O c := c * b b := 0 b := 0 b := 0 c := 0 23 Operating System Concepts 3.23 Silberschatz, Galvin and Gagne
  • 24. How process state changes6 Blocked Blocked Running The Next Process to Run cannot be simply selected a := 1 a := 1 a := 1 b := a + 1  read a file from the front1 b := a + c := b + 1 b := a + 1 c := b + 1  read a file c := b + 1  a := b - c a := b - c a := b - c c := c * b c := c * b c := c * b b := 0 b := 0 b := 0 c := 0 24 Operating System Concepts 3.24 Silberschatz, Galvin and Gagne
  • 25. How process state changes7 Blocked Blocked Running a := 1 a := 1 a := 1 b := a + 1  read a file b a := 1 1 := a + c := b + 1 b := a + 1 b := a + 1 c := b + 1  read a file c := b + 1  a c := b c 1 := b - + a := b - c a := b - c c a := * b c := c b - c :=Suppose the Green process finishesbI/O0 c * b c*b c := c * b  c := := b := 0 b := 0 b := 0 c := 0 c := 0 25 Operating System Concepts 3.25 Silberschatz, Galvin and Gagne
  • 26. How process state changes8 Blocked Ready Running a := 1 a := 1 a := 1 b := a + 1 read a file b a aa:= 1 :=:= 1 1 + c := b + 1  b := a + 1 b := a + 1 c :=bb:= a + 1 +1  read a file c := b + 1 c := b c 1 - +  a :=cb:= b + 1 a := b - c a := b - c c a ac:= b c c :=:= * b - b- c := c * b Timeout c := c * b  c := c * b b :=c0 c * b := b := 0 b := 0 c b b0:= 0 :=:= 0  := 0 c c := 0 26 Operating System Concepts 3.26 Silberschatz, Galvin and Gagne
  • 27. How process state changes9 Blocked Running Ready a := 1 a := 1 a := 1 b := a + 1 read a1file a := b := a + 1 c := b + 1 read+ 1file a :=a  b :=read 1 file a a c := b + 1  read a file b := a + 1 c :=bb + a1 a := b - c a := b - c  c :=:= c + 1 b+1 a :=cb - b + c := c * b c := c * b Timeout- c 1 := c a ac:= b - c :=:= * b b b := 0  := c * b b := 0 b c c0 c * b :=  c := 0 b :=:= 0 b := 0 27 Operating System Concepts 3.27 Silberschatz, Galvin and Gagne
  • 28. Process Creation s Reasons to create a process  Submit a new batch job/Start program  User logs on to the system  OS creates on behalf of a user (printing)  Spawned by existing process s Parent process create children processes, which, in turn create other processes, forming a tree of processes s Resource sharing q Parent and children share all resources q Children share subset of parent’s resources q Parent and child share no resources s Execution q Parent and children execute concurrently q Parent waits until children terminate Operating System Concepts 3.28 Silberschatz, Galvin and Gagne
  • 29. Process Creation (Cont.) s Address space q Child duplicate of parent q Child has a program loaded into it s UNIX examples q fork system call creates new process q exec system call used after a fork to replace the process’ memory space with a new program Operating System Concepts 3.29 Silberschatz, Galvin and Gagne
  • 30. Process Creation Operating System Concepts 3.30 Silberschatz, Galvin and Gagne
  • 31. 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); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); } } Operating System Concepts 3.31 Silberschatz, Galvin and Gagne
  • 32. The fork() system call At the end of the system call there is a new process waiting to run once the scheduler chooses it s A new data structure is allocated s The new process is called the child process. s The existing process is called the parent process. s The parent gets the child’s pid returned to it. s The child gets 0 returned to it. s Both parent and child execute at the same point after fork() returns 32 Operating System Concepts 3.32 Silberschatz, Galvin and Gagne
  • 33. Unix Process Control The fork syscall returns a zero to the child and the child process ID to the int pid; int status = 0; parent Parent uses wait to if (pid = fork()) { sleepFork creates an until the /* parent */ childexact copy of the exits; wait …… returns child pid parent process pid = wait(&status); and status. } else { /* child */ Wait variants …… allow wait on a exit(status); specific child, or } Child process of notification passes statusother stops and back to parent on exit, signals to report success/failure 33 Operating System Concepts 3.33 Silberschatz, Galvin and Gagne
  • 34. Process Termination s Batch job issues Halt instruction s User logs off s Process executes a service request to terminate s Parent terminates so child processes terminate s Operating system intervention q such as when deadlock occurs s Error and fault conditions q E.g. memory unavailable, protection error, arithmetic error, I/O failure, invalid instruction 34 Operating System Concepts 3.34 Silberschatz, Galvin and Gagne
  • 35. Process Termination s Process executes last statement and asks the operating system to delete it (exit) q Output data from child to parent (via wait) q Process’ resources are deallocated by operating system s Parent may terminate execution of children processes (abort) q Child has exceeded allocated resources q Task assigned to child is no longer required q If parent is exiting  Some operating system do not allow child to continue if its parent terminates – All children terminated - cascading termination Operating System Concepts 3.35 Silberschatz, Galvin and Gagne
  • 36. Inter process Communication Processes executing concurrently in the operating system may be either independent processes or cooperating processes. s Independent process cannot affect or be affected by the execution of another process s Cooperating process can affect or be affected by the execution of another process Operating System Concepts 3.36 Silberschatz, Galvin and Gagne
  • 37. Advantages of Process Cooperation s Information sharing: Allow concurrent access to same piece of information that several users may be interested in it. s Computation speed-up: break a task to subtasks, each of which will be executing in parallel with the others. (Should be multiple processing elements such as CPUs) s Modularity: divided the system functions into separate processes or threads. s Convenience: for user, user may work on many tasks at the same time. Operating System Concepts 3.37 Silberschatz, Galvin and Gagne
  • 38. MODELS OF IPC Cooperating processes require an inter process communication mechanism that will allow them to exchange data and information. 2. Shared Memory 3. Message Passing Operating System Concepts 3.38 Silberschatz, Galvin and Gagne
  • 39. SHARED MEMORY 1. Region of memory that is shared by cooperating processes is established. 2. Processes can then exchange information by reading and writing data to shared region Operating System Concepts 3.39 Silberschatz, Galvin and Gagne
  • 40. MESSAGE PASSING Communication takes place by means of messages exchanged between the cooperating processes. Operating System Concepts 3.40 Silberschatz, Galvin and Gagne
  • 41. Communications Models Operating System Concepts 3.41 Silberschatz, Galvin and Gagne
  • 42. Advantages & Disadvantages of Message Passing & Shared Memory 1. Message passing is useful for exchanging smaller amounts of data 2. Message Passing is easier to implement than shared memory for IPC 3. Shared Memory allows maximum speed and convenience as it can be done at memory speeds within a computer 4. Shared memory is faster than message passing as message passing is implemented using system calls. Operating System Concepts 3.42 Silberschatz, Galvin and Gagne
  • 43. Contd…. 1. Message passing requires the more time consuming task of kernel intervention. 2. Shared memory system calls are required only to establish shared memory regions, no assistance from the kernel is required. Operating System Concepts 3.43 Silberschatz, Galvin and Gagne
  • 44. Producer-Consumer Problem s Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process q A compiler may produce assembly code, which is consumed by an assembler. The assembler, in turn, may produce object modules, which are consumed by the loader s A buffer of items that can be filled by the producer and emptied by the consumer. should be available s A producer can produce one item while the consumer is consuming another item. s The producer and consumer must be synchronized q the consumer does not try to consume an item that has not yet been produced. q the consumer must wait until an item is produced Operating System Concepts 3.44 Silberschatz, Galvin and Gagne
  • 45. Producer-Consumer Problem s unbounded-buffer places no practical limit on the size of the buffer q the consumer may have to wait for new items, but q the producer can always produce new items s bounded-buffer assumes that there is a fixed buffer size q the consumer must wait if the buffer is empty, and q the producer must wait if the buffer is full. Operating System Concepts 3.45 Silberschatz, Galvin and Gagne
  • 46. Bounded-Buffer – Shared-Memory Solution s Shared data #define BUFFER_SIZE 10 Typedef struct { ... } item; item buffer[BUFFER_SIZE]; int in = 0; % in: the next free position in the buffer int out = 0; % out: the first full position in the buffer s The buffer is empty when in == out ; s The buffer is full when ((in + 1) % BUFFERSIZE) == out s Solution is correct, but can only use BUFFER_SIZE-1 elements Operating System Concepts 3.46 Silberschatz, Galvin and Gagne
  • 47. Bounded-Buffer – Insert() Method The producer process has a local variable nextproduced in which the new item to be produced is stored: while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; { Operating System Concepts 3.47 Silberschatz, Galvin and Gagne
  • 48. Bounded Buffer – Remove() Method The consumer process has a local variable nextconsumed in which the item to be consumed is stored: 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; { Operating System Concepts 3.48 Silberschatz, Galvin and Gagne
  • 49. Message Passing s Mechanism for processes to communicate and to synchronize their actions s Message system – processes communicate with each other without resorting to shared variables s IPC facility provides two operations: q send(message) – message size fixed or variable q receive(message) s If P and Q wish to communicate, they need to: q establish a communication link between them q exchange messages via send/receive s Implementation of communication link q physical (e.g., shared memory, hardware bus) q logical (e.g., logical properties) e.g. send(), receive() Operating System Concepts 3.49 Silberschatz, Galvin and Gagne
  • 50. Implementation Questions s How are links established? s Can a link be associated with more than two processes? s How many links can there be between every pair of communicating processes? s What is the capacity of a link? s Is the size of a message that the link can accommodate fixed or variable? s Is a link unidirectional or bi-directional? Operating System Concepts 3.50 Silberschatz, Galvin and Gagne
  • 51. Methods for logical implementation of link 1. Direct or Indirect Communication 2. Synchronous and Asynchronous Communication 3. Automatic or explicit Buffering Operating System Concepts 3.51 Silberschatz, Galvin and Gagne
  • 52. Direct Communication s Processes must name each other explicitly: q send (P, message) – send a message to process P q receive(Q, message) – receive a message from process Q s Properties of communication link q Links are established automatically because the processes need to know only the identities to communicate. q A link is associated with exactly one pair of communicating processes q Between each pair there exists exactly one link q The link may be unidirectional, but is usually bi-directional Operating System Concepts 3.52 Silberschatz, Galvin and Gagne
  • 53. Indirect Communication s Messages are directed and received from mailboxes (also referred to as ports) q Each mailbox has a unique id q Processes can communicate only if they share a mailbox s Properties of communication link q Link established only if processes share a common mailbox q A link may be associated with many processes q Each pair of processes may share several communication links q Link may be unidirectional or bi-directional Operating System Concepts 3.53 Silberschatz, Galvin and Gagne
  • 54. Indirect Communication s Operations q create a new mailbox q send and receive messages through mailbox q destroy a mailbox s Primitives are defined as: send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A Operating System Concepts 3.54 Silberschatz, Galvin and Gagne
  • 55. Indirect Communication s Mailbox sharing q P1, P2, and P3 share mailbox A q P1, sends; P2 and P3 receive q Who gets the message? s Solutions q Allow a link to be associated with at most two processes q Allow only one process at a time to execute a receive operation q Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was. Operating System Concepts 3.55 Silberschatz, Galvin and Gagne
  • 56. Indirect Communication s If the mailbox is owned by a process (that is, the mailbox is part of the address space of the process), q then we distinguish between the owner (who can only receive messages through this mailbox) and the user (who can only send messages to the mailbox). q Since each mailbox has a unique owner, there can be  no confusion about who should receive a message sent to this mailbox. q When a process that owns a mailbox terminates, the mailbox disappears. q Any process that subsequently sends a message to this mailbox must be notified that the mailbox no longer exists. Operating System Concepts 3.56 Silberschatz, Galvin and Gagne
  • 57. Indirect Communication s If a mailbox owned by the operating system is independent and is not attached to any particular process: q The operating system then must provide a mechanism that allows a process to do the following:  Create a new mailbox.  Send and receive messages through the mailbox.  Delete a mailbox q Note: the ownership and receive privilege may be passed to other processes through appropriate system calls. Operating System Concepts 3.57 Silberschatz, Galvin and Gagne
  • 58. Synchronization s Message passing may be either blocking or non-blocking s Blocking is considered synchronous q Blocking send has the sender block until the message is received q Blocking receive has the receiver block until a message is available s Non-blocking is considered asynchronous q Non-blocking send has the sender send the message and continue q Non-blocking receive has the receiver receive a valid message or null Operating System Concepts 3.58 Silberschatz, Galvin and Gagne
  • 59. Buffering s Queue of messages attached to the link; 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 Operating System Concepts 3.59 Silberschatz, Galvin and Gagne
  • 60. Client-Server Communication s Sockets s Remote Procedure Calls s Remote Method Invocation (Java) Operating System Concepts 3.60 Silberschatz, Galvin and Gagne
  • 61. Sockets s A socket is defined as an endpoint for communication s Concatenation of IP address and port s The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 s Communication consists between a pair of sockets Operating System Concepts 3.61 Silberschatz, Galvin and Gagne
  • 62. Socket Communication Operating System Concepts 3.62 Silberschatz, Galvin and Gagne
  • 63. Remote Procedure Calls s Remote procedure call (RPC) abstracts procedure calls between processes on networked systems. s Stubs – client-side proxy for the actual procedure on the server. s The client-side stub locates the server and marshalls the parameters. s The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server. s A stub is a small program routine that substitutes for a longer program, possibly to be loaded later or that is located remotely. For example, a program that uses Remote Procedure Calls ( RPC ) is compiled with stubs that substitute for the program that provides a requested procedure. The stub accepts the request and then forwards it (through another program) to the remote procedure. When that procedure has completed its service, it returns the results or other status to the stub which passes it back to the program that made the request. Operating System Concepts 3.63 Silberschatz, Galvin and Gagne
  • 64. Execution of RPC Operating System Concepts 3.64 Silberschatz, Galvin and Gagne