PROCESS MANAGEMENT - PowerPoint PPT Presentation

View by Category
About This Presentation



PROCESS MANAGEMENT. PROCESSES. CS433 Operating Systems. 2. Overview. Process Concept ... Memory management ... Process State Diagram. State names are arbitrary ... – PowerPoint PPT presentation

Number of Views:1482
Avg rating:3.0/5.0
Date added: 13 July 2020
Slides: 45
Provided by: course61
Learn more at:


Write a Comment
User Comments (0)
Transcript and Presenter's Notes



  • Process Concept
  • Process Scheduling
  • Operations on Processes
  • Cooperating Processes
  • Inter-process Communication
  • Communication in Client/Server Systems
  • Summary

Process Concept
  • What do you call all the CPUs activities?
  • A batch system executes jobs
  • A time-sharing system has user programs or tasks
  • Even a single-user system may be able to run
    several programs at one time
  • Word processor, web browser, e-mail package
  • The operating system may need to support its own
    internal programming activities
  • Memory management
  • In many respects, all these activities are
    similar, so we call them Processes
  • The term job and process are used almost
  • A process includes
  • program counter
  • stack
  • data section

Process in Memory
Process State
  • As a process executes, it changes state.
  • A state of a process is defined in part by the
    current activity of that process
  • Each process may be in one of the following
  • New
  • The process is being created
  • Running
  • Instructions are being executed
  • Waiting
  • The process is waiting for some event to occur
  • Ready
  • The process is ready to be assigned to a
  • Terminated
  • The process has finished execution

Process State Diagram
  • State names are arbitrary and vary across
    operating systems
  • The states they represent are found in all
  • Only one process may be running although many
    processes may be ready and waiting

Process Control Block
  • Process State
  • The state may be new, ready, running, waiting,
  • Program Counter
  • Indicates the address of the next instruction to
    be executed by the processor
  • CPU Registers
  • Vary in number and type, depending on the
    computer architecture
  • Include stack-pointer, general-purpose registers,
  • CPU-Scheduling Information
  • A process priority, pointers to scheduling queues
    and other scheduling parameters
  • Memory Management Information
  • Value of the base and limit registers, page
  • Accounting Information
  • Amount of CPU, account numbers, job or process
  • I/O Status Information
  • List of I/O devices allocated to a process, a
    list of files,

CPU Switch From Process to Process
Process Scheduling
  • The objective of multi-programming is to have
    some process running at all times
  • The objective of time-sharing is to switch the
    CPU among processes so frequently that users can
    interact with each program
  • A uniprocessor system can have only one running
  • If more processes exit, the rest must wait until
    the CPU is free and can be rescheduled

Scheduling Queues
  • Job Queue
  • Processes that just entered the system
  • This queue consists of all processes in the
  • Ready Queue
  • Processes residing in main memory that are ready
    and waiting to execute.
  • Typically stored as a linked-list
  • Device Queue
  • List of processes waiting for a particular device
  • Processes migrate among the various queues

Ready Queue and Various I/O Device Queues
Queuing Diagram
  • New processes wait in the ready queue for
  • Once the process is executing, one of several
    events could occur
  • Process could issue an I/O request, and then be
    placed on the I/O queue
  • Process could create a new process and wait for
    its termination
  • Process could be removed from the CPU as a result
    of an interrupt, and put back into the ready
  • A process continues this cycle until it
  • Process is then removed from all queues and has
    its PCB and resources de-allocated

  • The Scheduler
  • The selection process used by the operating
    system to migrate a process between the various
    scheduling queues
  • Long-Term Scheduler (Job Scheduler)
  • Selects which process should be brought into the
    ready queue
  • Short-Term Scheduler (CPU Scheduler)
  • Selects which process should be executed next and
    allocates the CPU
  • Processes can be described as either
  • I/O-bound process spends more time doing I/O
    than computations, many short CPU bursts
  • CPU-bound process spends more time doing
    computations few very long CPU bursts

Short-Term Scheduler
  • The short-term scheduler must select a new
    process for the CPU frequently
  • The short-term scheduler must be fast
  • A process may execute for only a few milliseconds
    before waiting for an I/O request

Long-Term Scheduler
  • The long-term scheduler executes much less
  • The long-term scheduler can afford to take more
    time to select a process
  • There may be minutes between the creation of new
  • The long-term scheduler controls the degree of
  • The number of processes in memory
  • The long-term scheduler should select a good
    process mix
  • I/O bound process (spends more time doing I/O)
  • If all processes are I/O bound, the ready-queue
    will be empty and the short-term scheduler will
    have little to do
  • CPU bound process (spends more time doing
  • If all process are CPU bound, the I/O queue will
    be empty, devices will go unused

Medium-Term Scheduler
  • The medium-scheduler may be used to reduce the
    degree of multi-programming
  • Removes processes from memory to be re-introduced
    later (known as swapping)
  • May be necessary to improve process mix
  • Memory needs to be freed up

Context Switch
  • The context switch task saves the state of the
    old process and loads the saved state of the new
    process when the CPU switches to another process
  • The context of the process is represented in the
  • Value of the CPU registers
  • Process state
  • Memory-management information
  • Context-switch time is pure overhead, because the
    system does no useful work while switching
  • Context-switch times are highly dependent on the
    hardware support

Operations On Processes
  • Because processes can be executed concurrently,
    they must be created and deleted dynamically.
  • The operating system must provide a mechanism for
    process creation and deletion of processes

Process Creation
  • Parent process create children processes, which,
    in turn create other processes, forming a tree of
  • Resource sharing
  • Parent and children share all resources
  • Children share subset of parents resources
  • Parent and child share no resources
  • Execution
  • Parent and children execute concurrently
  • Parent waits until children terminate
  • Address space
  • Child duplicate of parent
  • Child has a program loaded into it
  • UNIX examples
  • fork system call creates new process
  • exec system call used after a fork to replace the
    process memory space with a new program

Process Creation (Cont.)
  • A process will need certain resources to
    accomplish its task
  • CPU time, memory, files, I/O devices
  • Resource sharing among parents and children
  • Children may obtain their resources directly from
    the operating system
  • Parents share all their resources with the
  • Parents share a subset of their resources with
    the children
  • When a process creates a new process
  • The parent continues to execute concurrently with
    its children
  • The parent waits until some or all of its
    children have terminated.

Process Creation
C Program Forking Separate Process
int main() pid_t pid / fork another process
/ pid fork() if (pid lt 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)
Process Tree on a UNIX System
Process Termination
  • Process executes last statement and asks the
    operating system to delete it via the exit system
  • The process may return data (output) to its
    parent process via the wait system call
  • The process resources memory, open files, I/O
    buffers are de-allocated by the operating
  • A process can cause the termination of another
    process via a system call (abort)
  • Usually the parent can invoke such as system call
  • The parent may terminate the child for a variety
    of reasons
  • Child has exceeded the usage of its resources
  • Task assigned to the child is non longer required
  • If a process terminates then all of its children
    must also be terminated
  • Cascading termination

Cooperating Processes
  • Independent Processes
  • Cannot affect or be affected by other processes
    executing in the system
  • Does not share any data with any other process
  • Cooperating Processes
  • Can affect or be affected by other processes
    executing in the system
  • Shares data with other processes
  • Reasons for cooperating processes
  • Information Sharing
  • Computation speedup
  • Modularity
  • Convenience

Producer-Consumer Problem
  • A producer process produces information that is
    consumed by a consumer process
  • Print program ? characters gtgt printer driver
  • Compiler program ? assemble code gtgt assembler
  • Assembler ? object modules gtgt loader
  • To allow producer/consumer processes to run
    concurrently we need a buffer that can be filled
    by the producer and emptied by the consumer
  • The producer produces one item while the consumer
    consumes another item
  • The producer/consumer must be synchronized, so
    that the consumer does not try to consume an item
    that has not yet been produced

Producer-Consumer Buffer
  • Unbounded-Buffer
  • Places no practical limit on the size of the
  • Consumer may have to wait for new items, but the
    producer can always produce new items
  • Bounded Buffer
  • Assumes a fixed buffer size
  • The consumer must wait if the buffer is empty the
    producer must wait if the buffer is full
  • The buffer may be provided by the operating
    system via the inter-process-communication (IPC)
    facility or explicitly created by the application
    using shared memory

Bounded-Buffer Shared-Memory Solution
  • The shared buffer is implemented as a circular
    array with two logical pointers
  • The in variable points to the next free position
    in the buffer
  • The out variable points to the first full
    position in the buffer
  • Shared Data Variables
  • define BUFFER_SIZE 10
  • typedef struct
  • . . .
  • item
  • item bufferBUFFER_SIZE
  • int in 0
  • int out 0
  • Solution is correct, but can only use
    BUFFER_SIZE-1 elements

Bounded-Buffer Producer Process
  • The producer process stores the new item in the
    local variable nextProduced

item nextProduced while (1) while
(((in 1) BUFFER_SIZE) out) / do
nothing / bufferin nextProduced in
Bounded-Buffer Consumer Process
  • The consumer process stores the item to be
    consumed in the local variable nextConsumed
  • item nextProduced
  • while (1)
  • while (((in 1) BUFFER_SIZE) out)
  • / do nothing /
  • bufferin nextProduced
  • in (in 1) BUFFER_SIZE

Interprocess Communication (IPC)
  • Mechanism for processes to communicate and to
    synchronize their actions.
  • Message system processes communicate with each
    other without resorting to shared variables.
  • IPC facility provides two operations
  • send(message) message size fixed or variable
  • receive(message)
  • If P and Q wish to communicate, they need to
  • establish a communication link between them
  • exchange messages via send/receive
  • Implementation of communication link
  • physical (e.g., shared memory, hardware bus)
  • logical (e.g., logical properties)

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

Communications Models
Direct Communication
  • Each process must explicitly name the recipient
    or sender
  • send (P, msg) Send a message to P
  • receive (Q, msg) Receive a message from Q
  • This communication link has the following
  • A link is established automatically between every
    pair of processes
  • A link is associated with exactly two processes
  • Exactly one link exists between each pair of

Indirect Communication
  • Messages are directed and received from mailboxes
    (also referred to as ports).
  • Each mailbox has a unique id.
  • Processes can communicate only if they share a
  • Send (A, msg) Send a message to mailbox A
  • Receive (A, msg) Receive a message from mailbox
  • This communication link has the following
  • Link established only if processes share a common
  • A link may be associated with many processes.
  • Each pair of processes may share several
    communication links.
  • Link may be unidirectional or bi-directional.

  • Message passing may be either blocking or
  • Blocking is considered synchronous
  • Blocking Send
  • The sending process is blocked until the message
    is received by the receiving process
  • Blocking Receive
  • The receiver blocks until a message is available
  • Non-blocking is considered asynchronous
  • Non-blocking Send
  • The sending process sends the message and resumes
  • Non-blocking Receive
  • The receiver retrieve either a valid message or a

  • Whether the communication is direct or indirect,
    the messages reside in temporary queue
  • Zero capacity
  • The queue has a maximum length 0 thus the link
    cannot have any messages waiting in it.
  • Sender must block until the recipient receives
    the message
  • Bounded capacity
  • The queue has a finite length n thus at most n
    messages can reside in it.
  • If the queue is not full then the sender can
    place a message in the queue and continue
  • If the queue if full then the sender must block
    until space is available
  • Unbounded capacity
  • The queue has potential infinite length thus any
    number of messages can be sent. The sender never

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

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

Communication Using Sockets
Remote Procedure Calls
  • Remote procedure call (RPC) abstracts procedure
    calls between processes on networked systems.
  • Stubs client-side proxy for the actual
    procedure on the server.
  • The client-side stub locates the server and
    marshalls the parameters.
  • The server-side stub receives this message,
    unpacks the marshalled parameters, and performs
    the procedure on the server.

Execution of RPC
Remote Method Invocation
  • Remote Method Invocation (RMI) is a Java
    mechanism similar to RPCs.
  • RMI allows a Java program on one machine to
    invoke a method on a remote object.

Marshalling Parameters