PROCESS DESCRIPTION & CONTROL
Transcript of PROCESS DESCRIPTION & CONTROL
PROCESS DESCRIPTION & CONTROL
CHAPTER 2
CCS21203 OPERATING SYSTEM
Contents
A. Introduction of Process B. Process Description Control structure
Types of tables C. Process Control
i. Model of execution ii. process Creation iii. Process switching iv. Change of process state v. Execution of operating system
Recall on previous topic
The OS is viewed as ___________ that manage the system resources (???) by process.
Figure 1.1: Basic Diagram of Process and Resources
Introduction of Process
Process Thread Multithreading
An instance of execution of a program
A lightweight process which unit is smaller than a process. A thread is the entity within a process that can be scheduled for execution.
Allows application to manage a separate process with several threads of control
Requires main memory space during execution
Run in a shared memory space of a process
-
Passes through states such as running, ready, or waiting from its initial arrival into the computer system to its completion
Each thread maintains exception handlers, a scheduling priority, thread local storage, a unique thread identifier, and a set of structures the system will use to save the thread context until it is scheduled.
-
Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
The thread context includes the thread's set of machine registers, the kernel stack, a thread environment block, and a user stack in the address space of the thread's process.
-
Introduction of Process
• Elements of a process Program code May be shared with other processes that are executing the same
program
A set of data associated with the code When the processor begins to execute the program code, we refer
to this executing entity as a process
Process Control Block
For each process there is a Process Control Block, PCB, which stores the following
Process State Process ID, and parent process ID. CPU registers and Program Counter - These need to be saved
and restored when swapping processes in and out of the CPU. CPU-Scheduling information - Such as priority information
and pointers to scheduling queues. Memory-Management information - Page tables or segment
tables. Accounting information - user and kernel CPU time consumed,
account numbers I/O Status information - Devices allocated, open file tables.
Process States
Processes may be in one of 5 states: New/Hold - The process is in the stage of being created. Ready - The process has all the resources available that it
needs to run, but the CPU is not currently working on this process's instructions.
Running - The CPU is working on the process's instructions. Waiting - The process cannot run at the moment, because it is
waiting for some resource to become available or for some event to occur. For example the process may be waiting for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to finish.
Finished - The process has completed and return to the user.
Control Structure
An operating system, as a service provider, naturally also imposes control on processes that consume the services. That is both processes and resources are under the operating system’s control.
To enable this control, some facilities must be
provided, which is control tables.
Types of control tables
i. Memory table
ii. I/O table
iii. Files table
iv. Process table
i) Memory Table
To keep track of both main memory and secondary memory. Part of main memory is reserved to be used by the operating system while the remainder is available to be used by processes. Processes may also resize on secondary memory due to the utilization of swapping mechanism. The memory tables generally include the following information:
a. The allocation of main memory to processes b. The allocation of secondary memory to
processes c. Protection attributes of blocks of main or
virtual memory.
Swapping mechanism
Involves moving part of a process from main memory to secondary memory (disk).
When none of the processes in main memory is in the Ready state, the OS swaps one of the blocked processes out on to disk into a suspend queue.
Why process is suspended? 5 possible reasons
Differences between main and virtual memory
Main memory Physical DRAM SRAM
Virtual memory Originally invented to accommodate programs requiring more
memory than the physical memory. Replacement controlled by the operating system not hardware
ii) I/O tables
Are used by the operating system to manage I/O devices. Used by the OS to manage channels of the computer
system At any given time, an I/O device may be available or
assigned to a particular process
They should record: The availability of each particular device The status of I/O operations relating to each device The location in main memory ; either is being used as the source or
destination of the I/O transfer
iii) Files tables
Information is maintained and used by a file management system in which case the OS has little or no knowledge of files in other operating systems, much of the detail of file
management is managed by the OS itself
Files tables must have the information of: The existence of files Their (the file) location on secondary Their (the file) current status and Other attributes
iv) Process tables
Must be maintained to manage processes There must be some reference to memory, I/O, and files, directly or
indirectly The tables themselves must be accessible by the OS and therefore
are subject to memory management Contains what the operating system must know to manage and
control processes, including: i. Process location ii. Process attributes iii. Process identification (Process ID) iv. Process state information (Process State) v. Process control information (process CI) This may include scheduling and state information, data
structuring, process privileges, and resource ownerships.
Process Control 1. Model of execution 2. Process Creation and
termination 3. Process switching 4. Change of process state 5. Execution of operating system
Kernel Mode and User Mode
..\LECTURE\CHAPTER_1_forstudent.pptx Page 29
Process creation and termination
Process spawning When the OS create a process at explicit request of another
process
Parent process The original process that create a process
Child process Is a process created by the parent process
Process creation
Process Termination
There must be a means for a process to indicate its completion
A batch job should include a HALT instruction or an explicit OS service call for termination
For an interactive application, the action of the user will indicate when the process is completed (e.g. log off, quitting an application)
Process switching
A process switch may occur any time that the OS has gained control from the currently running process. Possible events giving OS control are:
Modes of switching
Interrupts
READ and WRITE command is issued to the CPU. Occur as a direct result of arithmetic operation: Attempt to divide by zero Floating-points operations generating an overflow or
underflow Fixed point addition or subtraction that cause arithmetic
overflow
Illegal job instructions, such as the following: Attempt to access protected or nonexistent storage location Attempt to use undefined operation code Operating on invalid data Attempt to make system changes
OVERFLOW and UNDERFLOW
Floating point operation generating an overflow or underflow is one of the interrupt reasons. Example of arithmetic operation overflow and underflow. If a numbers is represented using 4 bits as unsigned
binary, the minimum value is 0 (i.e., 00002, while the maximum value is 15 (11112).
Any operation that results in a number larger than 15 is overflow.
An operation that is smaller than 0 is underflow. For example, if you summed 14 + 14, the resulting
value is 28. but the value 28 has no representation using 4 bits
since the maximum representable value is 15 .
Process switching steps
1. Save the context of the processor 2. Update the related fields in the (process control
block) PCB, e.g. the state of the process. 3. Move the PCB to the appropriate queue. 4. Select another process for execution. 5. Update the PCB of the process selected. 6. Update memory management data 7. Restore the context of the processor to the one
when this selected process was last switched out.
Conclusion
It encourages the use of a modular operating system with clean interfaces between the modules.
Some noncritical operating system functions are conveniently implemented as separate processes.
The form of processes makes it possible to distribute different parts of the operating system in a multiprocessor environment, improving performance.