PROCESS MANAGEMENT - PowerPoint PPT Presentation

Loading...

PPT – PROCESS MANAGEMENT PowerPoint presentation | free to download - id: 15db-ZjY3O



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

PROCESS MANAGEMENT

Description:

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:1314
Avg rating:3.0/5.0
Slides: 45
Provided by: course61
Learn more at: http://courses.csusm.edu
Category:

less

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

Title: PROCESS MANAGEMENT


1
PROCESS MANAGEMENT
  • PROCESSES

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

3
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
    interchangeably
  • A process includes
  • program counter
  • stack
  • data section

4
Process in Memory
5
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
    states
  • 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
    processor
  • Terminated
  • The process has finished execution

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

7
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
    tables,
  • Accounting Information
  • Amount of CPU, account numbers, job or process
    numbers,
  • I/O Status Information
  • List of I/O devices allocated to a process, a
    list of files,

8
CPU Switch From Process to Process
9
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
    process.
  • If more processes exit, the rest must wait until
    the CPU is free and can be rescheduled

10
Scheduling Queues
  • Job Queue
  • Processes that just entered the system
  • This queue consists of all processes in the
    system
  • 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

11
Ready Queue and Various I/O Device Queues
12
Queuing Diagram
  • New processes wait in the ready queue for
    execution
  • 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
    queue
  • A process continues this cycle until it
    terminates
  • Process is then removed from all queues and has
    its PCB and resources de-allocated

13
Schedulers
  • 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

14
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

15
Long-Term Scheduler
  • The long-term scheduler executes much less
    frequently
  • The long-term scheduler can afford to take more
    time to select a process
  • There may be minutes between the creation of new
    processes
  • The long-term scheduler controls the degree of
    multi-programming
  • 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
    computations)
  • If all process are CPU bound, the I/O queue will
    be empty, devices will go unused

16
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

17
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
    PCB
  • 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

18
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

19
Process Creation
  • Parent process create children processes, which,
    in turn create other processes, forming a tree of
    processes
  • Resource sharing
  • Parent and children share all resources
  • Children share subset of parents resources
  • Parent and child share no resources
  • Execution
  • Parent and children execute concurrently
  • Parent waits until children terminate
  • 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

20
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
    children
  • 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.

21
Process Creation
22
C Program Forking Separate Process
int main() pid_t pid / fork another proce
ss / pid fork() if (pid curred / fprintf(stderr, "Fork Failed") ex
it(-1) else if (pid 0) / child proces
s / execlp("/bin/ls", "ls", NULL) else
/ parent process / / parent will wait for
the child to complete / wait (NULL) printf
("Child Complete") exit(0)
23
Process Tree on a UNIX System
24
Process Termination
  • Process executes last statement and asks the
    operating system to delete it via the exit system
    call
  • 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
    system
  • 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

25
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

26
Producer-Consumer Problem
  • A producer process produces information that is
    consumed by a consumer process
  • Print program ? characters printer driver
  • Compiler program ? assemble code assembler
  • Assembler ? object modules 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

27
Producer-Consumer Buffer
  • Unbounded-Buffer
  • Places no practical limit on the size of the
    buffer
  • 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

28
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

29
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 (in 1) BUFFER_SIZE
30
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

31
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)

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

33
Communications Models
34
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
    properties
  • 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
    processes

35
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
    mailbox.
  • Send (A, msg) Send a message to mailbox A
  • Receive (A, msg) Receive a message from mailbox
    A
  • This communication link has the following
    properties
  • Link established only if processes share a common
    mailbox
  • A link may be associated with many processes.
  • Each pair of processes may share several
    communication links.
  • Link may be unidirectional or bi-directional.

36
Synchronization
  • Message passing may be either blocking or
    non-blocking
  • 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
    operation
  • Non-blocking Receive
  • The receiver retrieve either a valid message or a
    null

37
Buffering
  • 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
    execution
  • 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
    blocks

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

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

40
Communication Using Sockets
41
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.

42
Execution of RPC
43
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.

44
Marshalling Parameters
About PowerShow.com