SlideShare una empresa de Scribd logo
1 de 65
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

Más contenido relacionado

La actualidad más candente

Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )HimanshuSharma1389
 
Cpu scheduling (1)
Cpu scheduling (1)Cpu scheduling (1)
Cpu scheduling (1)Ayush Oberai
 
cpu scheduling by shivam singh
cpu scheduling by shivam singhcpu scheduling by shivam singh
cpu scheduling by shivam singhshivam71291
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Shreya Kumar
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)Nagarajan
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt fileDwight Sabio
 
Process management in os
Process management in osProcess management in os
Process management in osMiong Lazaro
 
Ch6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinCh6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinShubham Singh
 
Deadlock : operating system ( BTECH CSE )
Deadlock : operating system ( BTECH CSE )Deadlock : operating system ( BTECH CSE )
Deadlock : operating system ( BTECH CSE )HimanshuSharma1389
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Nagarajan
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithmsPaurav Shah
 

La actualidad más candente (20)

Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )
 
Cpu scheduling (1)
Cpu scheduling (1)Cpu scheduling (1)
Cpu scheduling (1)
 
cpu scheduling by shivam singh
cpu scheduling by shivam singhcpu scheduling by shivam singh
cpu scheduling by shivam singh
 
Process
ProcessProcess
Process
 
Ch05
Ch05Ch05
Ch05
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
Scheduling
SchedulingScheduling
Scheduling
 
Process management in os
Process management in osProcess management in os
Process management in os
 
CPU Sheduling
CPU Sheduling CPU Sheduling
CPU Sheduling
 
Ch6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinCh6 CPU Scheduling galvin
Ch6 CPU Scheduling galvin
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
Deadlock : operating system ( BTECH CSE )
Deadlock : operating system ( BTECH CSE )Deadlock : operating system ( BTECH CSE )
Deadlock : operating system ( BTECH CSE )
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
 
scheduling algorithm
scheduling algorithmscheduling algorithm
scheduling algorithm
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 

Destacado (17)

Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 
Ch4
Ch4Ch4
Ch4
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Ch4
Ch4Ch4
Ch4
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Windows process-scheduling
Windows process-schedulingWindows process-scheduling
Windows process-scheduling
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
Operating Systems: Processor Management
Operating Systems: Processor ManagementOperating Systems: Processor Management
Operating Systems: Processor Management
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Insider operating system
Insider   operating systemInsider   operating system
Insider operating system
 
3 process management
3 process management3 process management
3 process management
 
Processes Control Block (Operating System)
Processes Control Block (Operating System)Processes Control Block (Operating System)
Processes Control Block (Operating System)
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
scheduling
schedulingscheduling
scheduling
 
Operating system overview concepts ppt
Operating system overview concepts pptOperating system overview concepts ppt
Operating system overview concepts ppt
 

Similar a OS Processes (20)

Chapter 3
Chapter 3Chapter 3
Chapter 3
 
OS-operating systems- ch03
OS-operating systems- ch03OS-operating systems- ch03
OS-operating systems- ch03
 
Processes
ProcessesProcesses
Processes
 
UNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdfUNIT - 3 PPT(Part- 1)_.pdf
UNIT - 3 PPT(Part- 1)_.pdf
 
OS_Unit II - Process Management_CATI.pptx
OS_Unit II - Process Management_CATI.pptxOS_Unit II - Process Management_CATI.pptx
OS_Unit II - Process Management_CATI.pptx
 
3 processes
3 processes3 processes
3 processes
 
ch3-lect7.pptx
ch3-lect7.pptxch3-lect7.pptx
ch3-lect7.pptx
 
Ch6
Ch6Ch6
Ch6
 
Chapter01
Chapter01Chapter01
Chapter01
 
Process concept
Process conceptProcess concept
Process concept
 
ch3 (1).ppt
ch3 (1).pptch3 (1).ppt
ch3 (1).ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Lecture_Process.ppt
Lecture_Process.pptLecture_Process.ppt
Lecture_Process.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3 s ppt
ch3 s                                  pptch3 s                                  ppt
ch3 s ppt
 
cs8493 - operating systems unit 2
cs8493 - operating systems unit 2cs8493 - operating systems unit 2
cs8493 - operating systems unit 2
 
Processes
ProcessesProcesses
Processes
 
Operating System
Operating SystemOperating System
Operating System
 
process management.ppt
process management.pptprocess management.ppt
process management.ppt
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

OS Processes

  • 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