Chapter 4: Processes - PowerPoint PPT Presentation

1 / 82
About This Presentation
Title:

Chapter 4: Processes

Description:

Suspended Processes. Processor is faster than I/O so all ... Blocked state becomes suspend state when swapped to disk. Two new states. Blocked, suspend ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 83
Provided by: marily185
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4: Processes


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

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

3
Process State
  • As a process executes, it changes state
  • new The process is being created.
  • running Instructions are being executed.
  • waiting The process is waiting for some event
    to occur.
  • ready The process is waiting to be assigned to
    a process.
  • terminated The process has finished execution.

4
Diagram of Process State
5
Process Control Block (PCB)
  • Information associated with each process.
  • Process state
  • Program counter
  • CPU registers
  • CPU scheduling information
  • Memory-management information
  • Accounting information
  • I/O status information

6
Process Control Block (PCB)
7
CPU Switch From Process to Process
8
Process Scheduling Queues
  • Job queue set of all processes in the system.
  • Ready queue set of all processes residing in
    main memory, ready and waiting to execute.
  • Device queues set of processes waiting for an
    I/O device.
  • Process migration between the various queues.

9
Ready Queue And Various I/O Device Queues
10
Representation of Process Scheduling
11
Schedulers
  • Long-term scheduler (or job scheduler) selects
    which processes should be brought into the ready
    queue.
  • Short-term scheduler (or CPU scheduler) selects
    which process should be executed next and
    allocates CPU.

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

14
Context Switch
  • When CPU switches to another process, the system
    must save the state of the old process and load
    the saved state for the new process.
  • Context-switch time is overhead the system does
    no useful work while switching.
  • Time dependent on hardware support.

15
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.

16
Process Creation (Cont.)
  • 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.

17
Processes Tree on a UNIX System
18
Process Termination
  • Process executes last statement and asks the
    operating system to decide it (exit).
  • Output data from child to parent (via wait).
  • Process resources are deallocated by operating
    system.
  • Parent may terminate execution of children
    processes (abort).
  • Child has exceeded allocated resources.
  • Task assigned to child is no longer required.
  • Parent is exiting.
  • Operating system does not allow child to continue
    if its parent terminates.
  • Cascading termination.

19
Cooperating Processes
  • Independent process cannot affect or be affected
    by the execution of another process.
  • Cooperating process can affect or be affected by
    the execution of another process
  • Advantages of process cooperation
  • Information sharing
  • Computation speed-up
  • Modularity
  • Convenience

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

21
Bounded-Buffer Shared-Memory Solution
  • Shared data
  • 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

22
Bounded-Buffer Producer Process
  • item nextProduced
  • while (1)
  • while (((in 1) BUFFER_SIZE) out)
  • / do nothing /
  • bufferin nextProduced
  • in (in 1) BUFFER_SIZE

23
Bounded-Buffer Consumer Process
  • item nextConsumed
  • while (1)
  • while (in out)
  • / do nothing /
  • nextConsumed bufferout
  • out (out 1) BUFFER_SIZE

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

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

26
Direct Communication
  • Processes must name each other explicitly
  • send (P, message) send a message to process P
  • receive(Q, message) receive a message from
    process Q
  • Properties of communication link
  • Links are established automatically.
  • A link is associated with exactly one pair of
    communicating processes.
  • Between each pair there exists exactly one link.
  • The link may be unidirectional, but is usually
    bi-directional.

27
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.
  • Properties of communication link
  • Link established only if processes share a common
    mailbox
  • A link may be associated with many processes.
  • Each pair of processes may share several
    communication links.
  • Link may be unidirectional or bi-directional.

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

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

30
Synchronization
  • Message passing may be either blocking or
    non-blocking.
  • Blocking is considered synchronous
  • Non-blocking is considered asynchronous
  • send and receive primitives may be either
    blocking or non-blocking.

31
Buffering
  • Queue of messages attached to the link
    implemented in one of three ways.
  • 1. Zero capacity 0 messagesSender must wait
    for receiver (rendezvous).
  • 2. Bounded capacity finite length of n
    messagesSender must wait if link full.
  • 3. Unbounded capacity infinite length Sender
    never waits.

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

33
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.

34
Socket Communication
35
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 peforms
    the procedure on the server.

36
Execution of RPC
37
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.

38
Marshalling Parameters
39
Major Requirements of anOperating System
  • Interleave the execution of several processes to
    maximize processor utilization while providing
    reasonable response time
  • Allocate resources to processes
  • Support interprocess communication and user
    creation of processes

40
Process
  • Also called a task
  • Execution of an individual program
  • Can be traced
  • list the sequence of instructions that execute

41
(No Transcript)
42
Process Creation
  • Submission of a batch job
  • User logs on
  • Created to provide a service such as printing
  • Process creates another process

43
Process Termination
  • Batch job issues Halt instruction
  • User logs off
  • Quit an application
  • Error and fault conditions

44
Reasons for Process Termination
  • Normal completion
  • Time limit exceeded
  • Memory unavailable
  • Bounds violation
  • Protection error
  • example write to read-only file
  • Arithmetic error
  • Time overrun
  • process waited longer than a specified maximum
    for an event

45
Reasons for Process Termination
  • I/O failure
  • Invalid instruction
  • happens when try to execute data
  • Privileged instruction
  • Data misuse
  • Operating system intervention
  • such as when deadlock occurs
  • Parent terminates so child processes terminate
  • Parent request

46
(No Transcript)
47
Using Two Queues
48
(No Transcript)
49
Suspended Processes
  • Processor is faster than I/O so all processes
    could be waiting for I/O
  • Swap these processes to disk to free up more
    memory
  • Blocked state becomes suspend state when swapped
    to disk
  • Two new states
  • Blocked, suspend
  • Ready, suspend

50
One Suspend State
51
Two Suspend States
52
Reasons for Process Suspension
53
(No Transcript)
54
Operating System Control Structures
  • Information about the current status of each
    process and resource
  • Tables are constructed for each entity the
    operating system manages

55
Memory Tables
  • Allocation of main memory to processes
  • Allocation of secondary memory to processes
  • Protection attributes for access to shared memory
    regions
  • Information needed to manage virtual memory

56
I/O Tables
  • I/O device is available or assigned
  • Status of I/O operation
  • Location in main memory being used as the source
    or destination of the I/O transfer

57
File Tables
  • Existence of files
  • Location on secondary memory
  • Current Status
  • Attributes
  • Sometimes this information is maintained by a
    file-management system

58
Process Table
  • Where process is located
  • Attributes necessary for its management
  • Process ID
  • Process state
  • Location in memory

59
Process Location
  • Process includes set of programs to be executed
  • Data locations for local and global variables
  • Any defined constants
  • Stack
  • Process control block
  • Collection of attributes
  • Process image
  • Collection of program, data, stack, and attributes

60
(No Transcript)
61
Process Control Block
  • Process identification
  • Identifiers
  • Numeric identifiers that may be stored with the
    process control block include
  • Identifier of this process
  • Identifier of the process that created this
    process (parent process)
  • User identifier

62
Process Control Block
  • Processor State Information
  • User-Visible Registers
  • A user-visible register is one that may be
    referenced by means of the machine language that
    the processor executes. Typically, there are from
    8 to 32 of these registers, although some RISC
    implementations have over 100.

63
Process Control Block
  • Processor State Information
  • Control and Status Registers
  • These are a variety of processor registers that
    are employed to control the operation of the
    processor. These include
  • Program counter Contains the address of the
    next instruction to be fetched
  • Condition codes Result of the most recent
    arithmetic or logical operation (e.g., sign,
    zero, carry, equal, overflow)
  • Status information Includes interrupt
    enabled/disabled flags, execution mode

64
Process Control Block
  • Processor State Information
  • Stack Pointers
  • Each process has one or more last-in-first-out
    (LIFO) system stacks associated with it. A stack
    is used to store parameters and calling addresses
    for procedure and system calls. The stack pointer
    points to the top of the stack.

65
Process Control Block
  • Process Control Information
  • Scheduling and State Information
  • This is information that is needed by the
    operating system to perform its scheduling
    function. Typical items of information
  • Process state defines the readiness of the
    process to be scheduled for execution (e.g.,
    running, ready, waiting, halted).
  • Priority One or more fields may be used to
    describe the scheduling priority of the process.
    In some systems, several values are required
    (e.g., default, current, highest-allowable)
  • Scheduling-related information This will depend
    on the scheduling algorithm used. Examples are
    the amount of time that the process has been
    waiting and the amount of time that the process
    executed the last time it was running.
  • Event Identity of event the process is awaiting
    before it can be resumed

66
Process Control Block
  • Process Control Information
  • Data Structuring
  • A process may be linked to other process in a
    queue, ring, or some other structure. For
    example, all processes in a waiting state for a
    particular priority level may be linked in a
    queue. A process may exhibit a parent-child
    (creator-created) relationship with another
    process. The process control block may contain
    pointers to other processes to support these
    structures.

67
Process Control Block
  • Process Control Information
  • Interprocess Communication
  • Various flags, signals, and messages may be
    associated with communication between two
    independent processes. Some or all of this
    information may be maintained in the process
    control block.
  • Process Privileges
  • Processes are granted privileges in terms of the
    memory that may be accessed and the types of
    instructions that may be executed. In addition,
    privileges may apply to the use of system
    utilities and services.

68
Process Control Block
  • Process Control Information
  • Memory Management
  • This section may include pointers to segment
    and/or page tables that describe the virtual
    memory assigned to this process.
  • Resource Ownership and Utilization
  • Resources controlled by the process may be
    indicated, such as opened files. A history of
    utilization of the processor or other resources
    may also be included this information may be
    needed by the scheduler.

69
(No Transcript)
70
Processor State Information
  • Contents of processor registers
  • User-visible registers
  • Control and status registers
  • Stack pointers
  • Program status word (PSW)
  • contains status information
  • Example the EFLAGS register on Pentium machines

71
Modes of Execution
  • User mode
  • Less-privileged mode
  • User programs typically execute in this mode
  • System mode, control mode, or kernel mode
  • More-privileged mode
  • Kernel of the operating system

72
Process Creation
  • Assign a unique process identifier
  • Allocate space for the process
  • Initialize process control block
  • Set up appropriate linkages
  • Ex add new process to linked list used for
    scheduling queue
  • Create of expand other data structures
  • Ex maintain an accounting file

73
When to Switch a Process
  • Clock interrupt
  • process has executed for the maximum allowable
    time slice
  • I/O interrupt
  • Memory fault
  • memory address is in virtual memory so it must be
    brought into main memory

74
When to Switch a Process
  • Trap
  • error occurred
  • may cause process to be moved to Exit state
  • Supervisor call
  • such as file open

75
Change of Process State
  • Save context of processor including program
    counter and other registers
  • Update the process control block of the process
    that is currently running
  • Move process control block to appropriate queue -
    ready, blocked
  • Select another process for execution

76
Change of Process State
  • Update the process control block of the process
    selected
  • Update memory-management data structures
  • Restore context of the selected process

77
Execution of the Operating System
  • Non-process Kernel
  • execute kernel outside of any process
  • operating system code is executed as a separate
    entity that operates in privileged mode
  • Execution Within User Processes
  • operating system software within context of a
    user process
  • process executes in privileged mode when
    executing operating system code

78
(No Transcript)
79
Execution of the Operating System
  • Process-Based Operating System
  • major kernel functions are separate processes
  • Useful in multi-processor or multi-computer
    environment

80
UNIX SVR4 Process Management
  • Most of the operating system executes within the
    environment of a user process

81
UNIX Process States
82
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com