CS代考 Process Description and Control

Process Description and Control

Topic Objectives
• Understand process states, state transition and their relationship with the dispatcher (process scheduler).

Copyright By PowCoder代写 加微信 powcoder

• Understand OS control structures, in particular, the process table and the role of PCB and its contents.
• Understand what constitutes the process image of a process.
• Understand mode switching and process switching and their
difference.
• Be aware of the overall structure of UNIX SVR4’s process management.
• Be aware of process related system calls in UNIX.

Readings • Stallings: Chapter 3

• A program in execution
• An instance of a program running on a computer
• The entity that can be assigned to and executed on a processor
• A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions

Process Elements
• Identifier
• Priority
• Program counter • Memory pointers • Context data
• I/O status information
• Accounting information

Process Control Block
• Contains the process elements
• Created and managed by the operating system • Allows support for multiple processes

Process Control Block

Trace of Process
• Sequence of instructions that execute for a process
• Dispatcher switches the processor from one process to another

Example Execution

Trace of Processes

Two-State Process Model
• Process may be in one of two states – Running
– Not-running

Not-Running Process in a Queue

• New batch job
Process Creation
– Onoldmainframecomputers,theoperatingsystemisprovidedwitha batch job control stream, usually on tape or disk. When the operating system is prepared to take on new work, it will read the next sequence of job control commands.
• Interactive logon
– A user at a terminal logs on to the system
• Created by OS to provide a service
– The operating system can create a process to perform a function on behalf of a user program, without the user having to wait (e.g., a process to control printing).
• Spawned by existing process
– Forpurposesofmodularityortoexploitparallelism,auserprogramcan dictate the creation of a number of processes.

Process Termination

Process Termination

Problem with Two-State Model
• Not-running
– ready to execute
– waiting for I/O
• Dispatcher cannot just select the process that has been in the queue the longest time because it may have been blocked

A Five-State Model
• Running • Ready
• Blocked • New

Five-State Process Model

Using Two Queues

Process States

Multiple Blocked Queues

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

One Suspend State

Two Suspend States

Reasons for Process Suspension

Operating System Control Structures
• Information about the current status of each process and resource
• Tables are constructed for each entity the operating system manages

Processes and Resources

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

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

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

Process Table
• Where process is located – program
– data – stack
• Attributes in the process control block – process identification
– processor state
– process control

Process Image

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
– User identifier

Processor State Information • Processor State Information
– Contents of processor registers • User-visible registers
• Control and status registers (PC and PSW) • Stack pointers
– Program status word (PSW)
• Contains status information
• Example: the EFLAGS register on Pentium machines

Pentium II EFLAGS Register

Process Control Block • ProcessControlInformation
– 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
• We will discuss processor scheduling in Topic 10.

Process Control Block • ProcessControlInformation
– 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.
• We will learn to use various interprocess communication mechanisms in UNIX systems in Topic 7.
– 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.

Process Control Block • ProcessControlInformation
– Memory Management
• This section may include pointers to segment and/or page tables that
describe the virtual memory assigned to this process.
• We will look at memory management issues in Topic 9.
– 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.

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.

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

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 or expand other data structures – Ex: maintain an accounting file

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, eg page fault

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

Switching Process
• Save context of processor including program counter and other registers
• Update the process control block of the process that is currently in the Running state
• Move process control block to appropriate queue – ready; blocked; ready/suspend
• Select another process for execution

Switching Process
• Update the process control block of the process selected
• Update memory-management data structures such as page table, a very expensive operation.
• Restore context of the selected process

Execution of the Operating System • Non-processKernel
– 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

Execution of the Operating System • Process-Based Operating System
– Implement operating system as a collection of system processes
– Useful in multi-processor or multi-computer environment

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

UNIX Process States

UNIX Process Image

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com