Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

CHAPTER 2

PROCESS DESCRIPTION &


CONTROL

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 To OS Process

Process Thread Multithreading


An instance of execution of a A lightweight process which unit is Allows application to
program smaller than a process. A thread is manage a separate
the entity within a process that can process with several
be scheduled for execution. threads of control

Requires main memory Run in a shared memory space of a -


space during execution process
Each thread maintains exception -
Passes through states such as handlers, a scheduling priority,
running, ready, or waiting thread local storage, a unique
from its initial arrival into thread identifier, and a set of
the computer system to its structures the system will use to
completion save the thread context until it is
scheduled.
Each process is started with a The thread context includes the -
single thread, often called the thread's set of machine registers,
primary thread, but can the kernel stack, a thread
create additional threads environment block, and a user
from any of its threads. stack in the address space of the
thread's process.
Why use threads?
5

 Allow a single application When in the Course of human events, it


becomes necessary for one people to
We hold these truths to be self-evident,
that all men are created equal, that they
destructive of these ends, it is the Right
of the People to alter or to abolish it,

to do many things at once


dissolve the political bands which have are endowed by their Creator with and to institute new Government,
connected them with another, and to certain unalienable Rights, that among laying its foundation on such principles
assume among the powers of the earth, these are Life, Liberty and the pursuit and organizing its powers in such form,
the separate and equal station to which of Happiness.--That to secure these as to them shall seem most likely to
the Laws of Nature and of Nature's God rights, Governments are instituted effect their Safety and Happiness.

 Simpler programming model


entitle them, a decent respect to the among Men, deriving their just powers Prudence, indeed, will dictate that
opinions of mankind requires that they from the consent of the governed, -- Governments long established should
should declare the causes which impel That whenever any Form of not be changed for light and transient
them to the separation. Government becomes causes; and accordingly all

 Less waiting
 Threads are faster to create
or destroy
 No separate address space
 Overlap computation and
I/O
 Could be done without
threads, but it’s harder
Kernel
 Example: word processor
 Thread to read from keyboard
 Thread to format document
 Thread to write to disk

Chapter 2 CS 1550, cs.pitt.edu (originaly


modified by Ethan L. Miller and
Benefits of Multithreading

Improved throughput. ...


Simultaneous and fully symmetric use of multiple
processors for computation and I/O.
Superior application responsiveness. ...
Improved server responsiveness. ...
Minimized system resource usage. ...
Program structure simplification. ...
Better communication
Introduction To 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.
When is a process created?
11

Processes can be created in two ways


 System initialization: one or more processes created when the
OS starts up
 Execution of a process creation system call: something
explicitly asks for a new process
System calls can come from
 User request to create a new process (system call executed from
user shell)
 Already running processes
 User programs
 System daemons- a computer program that runs as a background
process (eg. syslogd)

Chapter 2 CS 1550, cs.pitt.edu (originaly modified by Ethan L.


Miller and Scott A. Brandt)
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.

You might also like