0% found this document useful (0 votes)
26 views125 pages

Unit I and Unit II

Uploaded by

anyone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views125 pages

Unit I and Unit II

Uploaded by

anyone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 125

UNIT-I

Operating Systems Overview and Process Management: Definition, Operating


System Types, Operating System operations, Operating system services, System
calls and System Programs. Process concepts- Process, Process State Diagram, PCB
and Operations on processes, Process Scheduling- Scheduling Criteria and
Scheduling Algorithms.

OPERATING SYSTEMS OVERVIEW

1.1 Definition:

• An operating system is a program that acts as an interface between the user


and the computer hardware and controls the execution of all kinds of
programs.

• An operating system (OS) is system software that manages computer


hardware, software resources (such as a traffic controller, a scheduler, a
memory management module, I/O programs, and a file system), and
provides common services (memory, processors, devices, and information)
for computer programs.

• Operating system is the one program running at all times on the computer
(usually called the kernel), with all else being application programs.
Examples of Operating System are –
• Windows (GUI based, PC)
• GNU/Linux (Personal, Workstations, ISP, File and print server, Three-tier
client/Server)
• macOS (Macintosh), used for Apple’s personal computers and workstations
(MacBook, iMac).
• Android (Google’s Operating System for smartphones/tablets/smartwatches)
• iOS (Apple’s OS for iPhone, iPad, and iPod Touch)

Goals of Operating System are –


• Execute user programs and make solving user problems easier
• Make the computer system convenient to use
• Use the computer hardware in an efficient manner
FUNCTIONS of Operating System are –
Operating system performs four functions:
• Convenience: An OS makes a computer more convenient to use.
• Efficiency: An OS allows the computer system resources to be used
efficiently.
• Ability to Evolve: An OS should be constructed in such a way as to permit
the effective development, testing, and introduction of new system functions
at the same time without interfering with service.
• Throughput: An OS should be constructed so that It can give
maximum throughput (Number of tasks per unit time).
Major Functionalities of Operating System:
• Resource Management: When parallel accessing happens in the OS means
when multiple users are accessing the system the OS works as Resource
Manager, Its responsibility is to provide hardware to the user. It decreases
the load in the system.
• Process Management: It includes various tasks
like scheduling, termination of the process. OS manages various tasks at a
time. Here CPU Scheduling happens means all the tasks would be done by
the many algorithms that use for scheduling.
• Storage Management: The file system mechanism used for the
management of the storage. NIFS, CFS, CIFS, NFS, etc. are some file systems.
All the data stores in various tracks of Hard disks that all managed by the
storage manager. It included Hard Disk.
• Memory Management: Refers to the management of primary memory. The
operating system has to keep track, how much memory has been used and by
whom. It has to decide which process needs memory space and how much.
OS also has to allocate and deallocate the memory space.
• Security/Privacy Management: Privacy is also provided by the Operating
system by means of passwords so that unauthorized applications can’t access
programs or data. For example, Windows uses Kerberos authentication to
prevent unauthorized access to data.
1.2 Types / History of Operating Systems

1.3 Services of Operating System –
An operating system provides an environment for the execution of programs. It
provides certain services to programs and to the users of those programs.

Following are a few common services provided by an operating system −


• User Interface
• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection
• User Interface: Allows interacting with system. The various user interfaces are
• Command Line Interface: Uses text commands and a method for
entering them. Uses Command prompt. eg: shell (UNIX), DOS.
• Batch Interface: All the commands and directives are entered into files
and the file is executed.eg: shell script in UNIX/LINUX
• Graphical User Interface: The interface is a window system with a
pointing device to direct I/O, choose from menus, and make selections and
a keyboard to enter text. Eg: Windows, Apple Mac OS X, UNIX and Linux
have CLI with optional GUI interfaces.
One provides a command-line interface, or command interpreter, that allows
users to directly enter commands to be performed by the operating system. The
other allows users to interface with the operating system via a graphical user
interface, or GUI. Interpreters are known as shells. For example, on UNIX and
Linux systems, a user may choose among several different shells, including the
Bourne shell, Cshell, Bourne-Again shell, Korn shell, and others.
The main function of the command interpreter is to get and execute the next
user-specified command. Many of the commands given at this level manipulate
files: create, delete, list, print, copy, execute, and so on. The MS-DOS and UNIX
shells operate in this way.

• Program Execution:
• The system must be able to load program into memory and to run that
program.
• The program must end its execution either normally or abnormally
(Indicating error).
• I/O Operations: A running program may require I/O, for efficiency and
protection; users usually cannot control I/O devices directly. Hence Operating
system has to perform I/O.
• File System Manipulation: For files
• Files can be created, deleted, searched by name
• File permissions to allow or deny access to file or directory based on
ownership.
• Programs need to read and write files and directories.
• Organizing file system structure
All these services must be provided by Operating System.
• Communications:
• One process needs to exchange information with another process.
• Process communication occurs between two processes that are executing
on same computer or different computers in a network.
• Operating system provides process communication by using pipes, shared
memory and message passing.
• Error Detection: Operating system needs to be constantly aware of possible
errors and it has to take appropriate action to ensure correct and consistent
computing. The errors may occur in
• CPU, Memory (Power failure, Timer error, Memory Insufficient)
• I/O Devices (Parity errors, Printer Errors, Connection failure in network).
• User Program (Arithmetic Overflow, Illegal memory access, use of more
CPU time)

The services those are helpful to for efficient operation of the system can be
• Resource Allocation: Operating system has to manage different types of
resources. When multiple users or multiple jobs running at the same time, the OS
has to allocate the resources. The recourses can be
• CPU clock cycles (CPU Time)
• Main Memory
• File Storage (Disks)
• I/O Devices
• Accounting: The operating system has to record and keep track of which
users howmuch and what kind of resources.
This information is for
• Accounting (Billing)
• Using statistics, the researchers can reconfigure system to improve
computing services.
• Protection & Security:
• When several process executing concurrently they should not interfere
with others or with the operating system. Protection involves ensuring
that all accessto the system resources is controlled.
• In a multi user and networked systems, the file and I/O system access
must be secured from unauthorized access. Security must ensure from
external attacks.
1.4 Operations of Operating-Systems
• Shell is a UNIX term for the interactive user interface with an operating system.
The shell is the layer of programming that understands and executes the
commands a user enters. In some systems, the shell is called a command
interpreter then shell is a set of UNIX commands.
• Bootstrap program is loaded at power-up or reboot
• Typically stored in ROM or EPROM, generally known as firmware
• Initializes all aspects of system
• Loads operating system kernel and starts execution.
• A compiler is a program that accepts a source program in a “high-level
language” and produces a corresponding object program.
• Interpreter: --- An interpreter is a program that appears to execute a source
program as if it was machine language.
• Loader: --- the loader must load, relocate, and link the object program. Loader is a
program that places programs into memory and prepares them for execution.
• High Level Language à Assembly Language à Machine Level Language
• Assembler: ---- is Software that converts an assembly language code to
machine code. It takes basic Computer commands and converts them into Binary
Code that Computer's Processor can use to perform its Basic Operations.

Most of the operating systems are Interrupt Driven. An operating system performs any
servicewith an event. Events are signaled by an interrupt or trap (exception).
• A trap (or an exception) is a software-generated interrupt caused either by an
error (for example, division by zero or invalid memory access) or by a specific
request from a user program that an operating-system service be performed.
The interrupt can be
• Hardware interrupts: By any one of the devices
• Software Interrupts: interrupt or trap
• Software error (e.g., division by zero)
• Request for operating system service
• Process problems include infinite loop, processes modifying each
other orthe operating system

For each type of interrupt, separate segment of code (Interrupt Service Routine-ISR)
in the operating system determine what action is taken. Since the operating system and
users share the hardware and software resources of the computer, Operating system
must ensure that an incorrect program cannot cause other programs to execute
incorrectly.
For this, operating systems uses
1. Dual Mode operation:
To ensure the proper execution of operating systems, we must be able to
distinguishbetween the execution of operating-system code and user defined code.

OS Programs / ISRs – Kernel

Main Memory

User Programs - User

Mostly, the CPU is operated in two modes (Dual Mode)

Two separate modes of operation: user mode and kernel mode (also called supervisor
mode, system mode, or privileged mode).
• User Mode / Non- Privileged Mode: The computer system is operated on
behalf of auser application i.e executes user program.
• System / Privileged / supervisor/ Kernel Mode: The computer system
executed operatingsystem programs to obtain the system services.
When a user program requires the service of an operating system, the CPU switches from
user tokernel mode.
• Kernel: --- “The one program running at all times on the computer”. Everything
else is either a system program (ships with the operating system) or an
application program.

The transition from User to Kernel Mode


A bit, called the mode bit, is added to the hardware of the computer to indicate the
current mode: kernel (0) or user (1). With the mode bit, we can distinguish between a
task that is executed on behalf of the operating system and one that is executed on
behalf of the user. When the computer system is executing on behalf of a user
application, the system is in user mode. However, when a user application requests a
service from the operating system (via a system call), the system must transition from
user to kernel mode to fulfill the request. When a system call is executed, it is treated by
CPU as Software Interrupt. It causes to switch from user mode to system mode or vice
versa. The instruction to switch from user mode to kernel mode is a Privileged
instruction.

At system boot time, the hardware starts in kernel mode. The operating system is
then loaded and starts user applications in user mode. Whenever a trap or interrupt
occurs, the hardware switches from user mode to kernel mode (that is, changes the state
of the mode bit to 0). Thus, whenever the operating system gains control of the computer,
it is in kernel mode. The system always switches to user mode (by setting the mode bit to
1) before passing control to a user program.

The hardware allows privileged instructions to be executed only in kernel mode. If


an attempt is made to execute a privileged instruction in user mode, the hardware does
not execute the instruction but rather treats it as illegal and traps it to the operating
system. The instruction to switch to kernel mode is an example of a privileged
instruction. Some other examples include I/O control, timer management, and interrupt
management.

System calls provide the means for a user program to ask the operating system to
perform tasks reserved for the operating system on the user program’s behalf. A system
call is invoked in a variety of ways, depending on the functionality provided by the
underlying processor. In all forms, it is the method used by a process to request action by
the operating system. A system call usually takes the form of a trap to a specific location
in the interrupt vector. This trap can be executed by a generic trap instruction, although
some systems (such as MIPS) have a specific syscall instruction to invoke a system call.

When a system call is executed, it is typically treated by the hardware as software


interrupt. Control passes through the interrupt vector to a service routine in the
operating system, and the mode bit is set to kernel mode. The system-call service routine
is a part of the operating system. The kernel examines the interrupting instruction to
determine what system call has occurred; a parameter indicates what type of service the
user program is requesting.

The Life cycle of execution in a system is


• Initially Control resides in Operating System, Where instructions are executed in
KernelMode.
• When control is given to the user application based on interrupt, the mode is
set touser mode.
• Eventually, control is switched back to the operating system via a trap,
interrupt or asystem call.

Most of the operating systems Windows, UNIX, LINUX, and Solaris use Dual-Mode
operation to protect the system.
• Timer:
The operating system maintains control over the CPU.
Example: Operating System cannot allow
• A user program to get stuck in infinite loop
• Fail to call system services
• Never return control to the operating systemto avoid this, a timer is used.
• A timer can be set to interrupt the computer after a specified period of time.
• The period may be fixed or variable, set by operating system.
• A variable timer generally implemented by a fixed rate clock and a counter. The OS
sets the counter. Every time the clock ticks, the counter is decremented. When the
counter reaches 0, an interrupt occurs.
• A privileged instruction can only modify the content of timer.

• Process Management
A program does nothing unless its instructions are executed by a CPU. A program in
execution, as mentioned, is a process. A time-shared user program such as a compiler
is a process. A word-processing program being run by an individual user on a PC is a
process. A system task, such as sending output to a printer, can also be a process (or
at least part of one).

A process needs certain resources—including CPU time, memory, files, and I/O
devices—to accomplish its task. These resources are either given to the process when it is
created or allocated to it while it is running. In addition to the various physical and logical
resources that a process obtains when it is created, various initialization data (input) may
be passed along.

A single-threaded process has one program counter specifying the next instruction
to execute. The execution of such a process must be sequential. The CPU executes one
instruction of the process after another, until the process completes. A multithreaded
process has multiple program counters, each pointing to the next instruction to execute
for a given thread.
A process is the unit of work in a system. A system consists of a collection of
processes, some of which are operating-system processes (those that execute system
code) and the rest of which are user processes (those that execute user code).
The operating system is responsible for the following activities in connection with
process management:

Process Management Activities


• Scheduling processes and threads on the CPUs
• Creating and deleting both user and system processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• A process is a program in execution. It is a unit of work within the system.
Program is a passive entity; process is an active entity.
• Process needs resources to accomplish its task
• Process termination requires reclaim of any reusable resources
• Single-threaded process has one program counter specifying location of next
instruction to execute
• Process executes instructions sequentially, one at a time, until completion
• Multi-threaded process has one program counter per thread
• Typically, system has many processes, some user, some operating system
running concurrently on one or more CPUs

• Memory Management
The main memory is central to the operation of a modern computer system. Main
memory is a large array of bytes, ranging in size from hundreds of thousands to
billions. Each byte has its own address. Main memory is a repository of quickly
accessible data shared by the CPU and I/O devices. The central processor reads
instructions from main memory during the instruction-fetch cycle and both reads and
writes data from main memory during the data-fetch cycle.

For a program to be executed, it must be mapped to absolute addresses and


loaded into memory. As the program executes, it accesses program instructions and
data from memory by generating these absolute addresses. Eventually, the program
terminates, its memory space is declared available, and the next program can be
loaded and executed.

To improve both the utilization of the CPU and the speed of the computer’s
response to its users, general-purpose computers must keep several programs in
memory, creating a need for memory management.
Memory management activities
• Keeping track of which parts of memory are currently being used and by whom
• Deciding which processes (or parts thereof) and data to move into and out of
memory
• Allocating and deallocating memory space as needed

• Storage Management
To make the computer system convenient for users, the operating system provides a
uniform, logical view of information storage. The operating system abstracts from the
physical properties of its storage devices to define a logical storage unit, the file. The
operating system maps files onto physical media and accesses these files via the
storage devices.
• File-System Management
File management is one of the most visible components of an operating system.
Computers can store information on several different types of physical media. Magnetic
disk, optical disk, and magnetic tape are the most common. Each of these media has its
own characteristics and physical organization. Each medium is controlled by a device,
such as a disk drive or tape drive, that also has its own unique characteristics. These
properties include access speed, capacity, data-transfer rate, and access method
(sequential or random).

A file is a collection of related information defined by its creator. Commonly, files


represent programs (both source and object forms) and data. Data files may be numeric,
alphabetic, alphanumeric, or binary.
OS File Management activities
• Creating and deleting files and directories
• Primitives to manipulate files and directories
• Mapping files onto secondary storage
• Backup files onto stable (non-volatile) storage media
• Mass-Storage Management
The operating system is responsible for the following activities in connection with disk
management:
• Free-space management
• Storage allocation
• Disk scheduling

Magnetic tape drives and their tapes and CD and DVD drives and platters are typical
tertiary storage devices.

• Caching
When we need a particular piece of information, we first check whether it is in the cache.
If it is, we use the information directly from the cache. If it is not, we use the information
from the source, putting a copy in the cache under the assumption that we will need it
again soon.

In addition, internal programmable registers, such as index registers, provide a


high-speed cache for main memory. The programmer (or compiler) implements the
register-allocation and register-replacement algorithms to decide which information to
keep in registers and which to keep in main memory.

Other caches are implemented totally in hardware. For instance, most systems
have an instruction cache to hold the instructions expected to be executed next. Without
this cache, the CPU would have to wait several cycles while an instruction was fetched
from main memory. Because caches have limited size, cache management is an important
design problem. Careful selection of the cache size and of a replacement policy can result
in greatly increased performance.
Main memory can be viewed as a fast cache for secondary storage, since data in
secondary storage must be copied into main memory for use and data must be in main
memory before being moved to secondary storage for safekeeping. The file-system data,
which resides permanently on secondary storage, may appear on several levels in the
storage hierarchy. At the highest level, the operating system may maintain a cache of file-
system data in main memory.

I/O Subsystem
The I/O subsystem consists of several components:
• A memory-management component that includes buffering, caching, and spooling
• A general device-driver interface
• Drivers for specific hardware devices

Protection and Security


Protection, then, is any mechanism for controlling the access of processes or users to the
resources defined by a computer system.

Protection and security require the system to be able to distinguish among all its
users. Most operating systems maintain a list of user names and associated user
identifiers (user IDs). In Windows parlance, this is a security ID (SID). These numerical
IDs are unique, one per user. When a user logs in to the system, the authentication stage
determines the appropriate user ID for the user. That user ID is associated with all of the
user’s processes and threads. When an ID needs to be readable by a user, it is translated
back to the user name via the user name list.
In some circumstances, we wish to distinguish among sets of users rather than individual
users. For example, the owner of a file on a UNIX system may be allowed to issue all
operations on that file, whereas a selected set of users may be allowed only to read the
file. To accomplish this, we need to define a group name and the set of users belonging to
that group. Group functionality can be implemented as a system-wide list of group names
and group identifiers. A user can be in one or more groups, depending on operating-
system design decisions. The user’s group IDs are also included in every associated
process and thread.
• Systems generally first distinguish among users, to determine who can do what
• User identities (user IDs, security IDs) include name and associated number, one
per user
• User ID then associated with all files, processes of that user to determine access
control
• Group identifier (group ID) allows set of users to be defined and controls
managed, then also associated with each process, file
• Privilege escalation allows user to change to effective ID with more rights

1.6 SYSTEM CALLS


System calls provide an interface to the services made available by an operating
system. These calls are generally available as routines written in C and C++, although
certain low-level tasks (for example, tasks where hardware must be accessed
directly) may have to be written using assembly-language instructions. An example
to illustrate how system calls are used: writing a simple program to read data from
one file and copy them to another file.

Frequently, systems execute thousands of system calls per second. Typically,


application developers design programs according to an application programming
interface (API). The API specifies a set of functions that are available to an
application programmer, including the parameters that are
Passed to each function and the return values the programmer can expect. Three of
the most common APIs available to application programmers are the Windows API
for Windows systems, the POSIX API for POSIX-based systems(which include
virtually all versions of UNIX, Linux, and Mac OSX), and the Java API for programs
that run on the Java virtual machine. A programmer accesses an API via a library of
code provided by the operating system. In the case of UNIX and Linux for programs
written in the C language, the library is called libc.

The functions that make up an API typically invoke the actual system calls on
behalf of the application programmer. For example, the Windows function
CreateProcess () (which unsurprisingly is used to create a new process) actually
invokes the NT CreateProcess () system call in the Windows kernel.

For most programming languages, the run-time support system (a set of functions built
into libraries included with a compiler) provides a system call interface that serves as
the link to system calls made available by the operating system. The system-call interface
intercepts function calls in the API and invokes the necessary system calls within the
operating system.

Types of System Calls


• Process control
• File management
• Device management
• Information maintenance
• Communications
• Protection
Process Control
A running program needs to be able to halt its execution either normally (end ()) or
abnormally (abort ()). If a system call is made to terminate the currently running
program abnormally, or if the program runs into a problem and causes an error trap, a
dump of memory is sometimes taken and an error message generated. The dump is
written to disk and may be examined by a debugger—a system program designed to aid
the programmer in finding and correcting errors, or bugs—to determine the cause of
the problem. Under either normal or abnormal circumstances, the operating system
must transfer control to the invoking command interpreter. The command interpreter
then reads the next command.
FreeBSD (derived from Berkeley UNIX) is an example of a multitasking system. When a
user logs on to the system, the shell of the user’s choice is run. This shell is similar to the
MS-DOS shell in that it accepts commands and executes programs that the user requests.
However, since FreeBSD is a multitasking system, the command interpreter may continue
running while another program is executed (Figure 2.10).

To start a new process, the shell executes a fork() system call. Then, the selected program
is loaded into memory via an exec() system call, and the program is executed. Depending
on the way the command was issued, the shell then either waits for the process to finish
or runs the process “in the background.”

File Management
We first need to be able to create () and delete () files. Either system call requires the
name of the file and perhaps some of the file’s attributes. Once the file is created, we need
to open () it and to use it. We may also read (), write (), or reposition () (rewind or skip to
the end of the file, for example). Finally, we need to close () the file, indicating that we are
no longer using it.

Device Management
Process may need several resources to execute—main memory, disk drives, access to
files, and so on. If the resources are available, they can be granted, and control can be
returned to the user process. Otherwise, the process will have to wait until sufficient
resources are available. The various resources controlled by the operating system can be
thought of as devices. Some of these devices are physical devices (for example, disk
drives), while others can be thought of as abstract or virtual devices (for example, files). A
system with multiple users may require us to first request () a device, to ensure exclusive
use of it. After we are finished with the device, were lease () it. Once the device has been
requested (and allocated to us), we can read (), write (), and (possibly) reposition () the
device, just as we can with files.

Information Maintenance
Many system calls exist simply for the purpose of transferring information between the
user program and the operating system. For example, most systems have a system call to
return the current time () and date (). Other system calls may return information about
the system, such as the number of current users, the version number of the operating
system, the amount of free memory or disk space, and so on. Another set of system calls is
helpful in debugging a program. Many systems provide system calls to dump () memory.
This provision is useful for debugging.

Communication
There are two common models of inter process communication: the message passing
model and the shared-memory model. In the message-passing model, the communicating
processes exchange messages with one another to transfer information. Messages can be
exchanged between the processes either directly or indirectly through a common
mailbox. Before communication can take place, a connection must be opened.

Each computer in a network has a host name by which it is commonly


known. A host also has a network identifier, such as an IP address. Similarly, each process
has a process name, and this name is translated into an identifier by which the operating
system can refer to the process. The get hostid() and get processid()system calls do this
translation. The identifiers are then passed to the general purpose open () and close()
calls provided by the file system or to specific open connection () and close connection ()
system calls, depending on the system’s model of communication. The recipient process
usually must give its permission for communication to take place with an accept
connection () call.

In the shared-memory model, processes use shared memory create()and shared memory
attach() system calls to create and gain access to regions of memory owned by other
processes.

Protection
Protection provides a mechanism for controlling access to the resources provided by a
computer system. Typically, system calls providing protection include set permission
()and get permission (), which manipulate the permission settings of resources such as
files and disks. The allow user () and deny user() system calls specify whether particular
users can—or cannot—be allowed access to certain resources.
1.7 SYSTEM PROGRAMS
System programs, also known as system utilities, provide a convenient environment for
program development and execution. Some of them are simply user interfaces to system
calls. Others are considerably more complex. They can be divided into these categories:
• File management: These programs create, delete, copy, rename, print, dump, list,
and generally manipulate files and directories.
• Status information: Some programs simply ask the system for the date, time,
amount of available memory or disk space, number of users, or similar status
information. Others are more complex, providing detailed performance, logging,
and debugging information.
• Some ask the system for info - date, time, amount of available memory, disk
space, number of users
• Others provide detailed performance, logging, and debugging information
• Typically, these programs format and print the output to the terminal or
otheroutput devices
• Some systems implement a registry - used to store and retrieve
configurationinformation
• File modification: Several text editors may be available to create and modify the
content of files stored on disk or other storage devices. There may also be special
commands to search contents of files or perform transformations of the text.
• Programming-language support: Compilers, assemblers, debuggers, and
interpreters for common programming languages (such as C, C++, Java, and PERL)
are often provided with the operating system or available as a separate download.
• Program loading and execution: Once a program is assembled or compiled, it
must be loaded into memory to be executed. The system may provide absolute
loaders, relocatable loaders, linkage editors, and overlay loaders. Debugging
systems for either higher-level languages or machine language are needed as well.
• Communications: Provide the mechanism for creating virtual connections among
processes, users, and computer systems.
• Allow users to send messages to one another’s screens, browse web pages, send
electronic-mail messages, and log in remotely, transfer files from one machine to
another etc.
• Application Programs: Operating system provides programs like web browsers,
word processors, text formatters, database systems, compilers, games and
statistical packages.
• Background services: All general-purpose systems have methods for launching
certain system-program processes at boot time. Some of these processes
terminate after completing their tasks, while others continue to run until the
system is halted. Constantly running system-program processes are known as
services, subsystems, or daemons.
Along with system programs, most operating systems are supplied with programs that
are useful in solving common problems or performing common operations. Such
application programs include Web browsers, word processors and text formatters,
spreadsheets, database systems, compilers, plotting and statistical-analysis packages, and
games.

PROCESS MANAGEMENT OR PROCESS CONCEPTS


INTRODUCTION
1.6 Process:
A process is basically a program in execution. The execution of a process must progress in
a sequential fashion. A process is defined as an entity which represents the basic unit
of work to be implemented in the system. To put it in simple terms, we write our
computer programs in a text file and when we execute this program, it becomes a process
which performs all the tasks mentioned in the program.
A process is also known as job or task. A process is more than the program code,
which is sometimes known as the text section. It also includes the current activity, as
represented by the value of the program counter and the contents of the processor’s
registers. A process generally also includes the process stack, which contains temporary
data (such as function parameters, return addresses, and local variables), and a data
section, which contains global variables. A process may also include a heap, which is
memory that is dynamically allocated during process run time. The structure of a process
in memory is shown in Figure 3.1.
S.N. Component & Description

1 Stack
The process Stack contains the temporary data such as method/function
parameters, return address and local variables.

2 Heap
This is dynamically allocated memory to a process during its run time.

3 Text
This includes the current activity represented by the value of Program Counter
and the contents of the processor's registers.

4 Data
This section contains the global and static variables.

Program
A program is a passive entity, such as a file containing a list of instructions stored on
disk (often called an executable file). In contrast, a process is an active entity, with a
program counter specifying the next instruction to execute and a set of associated
resources. A program becomes a process when an executable file is loaded into
memory. A program is a piece of code which may be a single line or millions of lines.
A computer program is usually written by a computer programmer in a programming
language. For example, here is a simple program written in C programming language

#include <stdio.h>
int main ()
{
printf("Hello, World! \n");
return 0;
}
A computer program is a collection of instructions that performs a specific task when
executed by a computer. When we compare a program with a process, we can conclude
that a process is a dynamic instance of a computer program.
A part of a computer program that performs a well-defined task is known as
an algorithm. A collection of computer programs, libraries and related data are referred
to as software.

1.7 Process State


As a process executes, it changes state. The state of a process is defined in part by the
current activity of that process. A process may be in one of the following states:

Process Life Cycle


When a process executes, it passes through different states. These stages may differ
in different operating systems, and the names of these states are also not
standardized. A process can have one of the following five states at a time.

S.NO State & Description

1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are waiting
to have the processor allocated to them by the operating system so that they can
run. Process may come into this state after Start state or while running it by but
interrupted by the scheduler to assign CPU to some other process.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such as
waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
system, it is moved to the terminated state where it waits to be removed from
main memory.

The state diagram corresponding to this state is presented in Figure 3.2.


2.3 Process Control Block
Each process is represented in the operating system by a process control block (PCB)—
also called a Task control block. It contains many pieces of information associated with
a specific process, including these:

• Program counter. The counter indicates the address of the next instruction to be
executed for this process.
• CPU registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information. Along with the program counter,
this state information must be saved when an interrupt occurs, to allow the process to be
continued correctly afterward (Figure 3.4).
• CPU-scheduling information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
• Memory-management information. This information may include such items as the
value of the base and limit registers and the page tables, or the segment tables, depending
on the memory system used by the operating system.
• Accounting information. This information includes the amount of CPU and real time
used, time limits, account numbers, job or process numbers, and so on.
• I/O status information. This information includes the list of I/O devices allocated to
the process, a list of open files, and so on.
In brief, the PCB simply serves as the repository for any information that may vary from
process to process.

1.9 OPERATIONS ON PROCESSES


The processes in most systems can execute concurrently, and they may be created and
deleted dynamically.
Process Creation
During the course of execution, a process may create several new processes. As
mentioned earlier, the creating process is called a parent process, and the new processes
are called the children of that process. Each of these new processes may in turn create
other processes, forming a tree of processes. Most operating systems (including UNIX,
Linux, and Windows) identify processes according to a unique process identifier (or
pid), which is typically an integer number. The pid provides a unique value for each
process in the system, and it can be used as an index to access various attributes of a
process within the kernel.
When a process creates a new process, two possibilities for execution exist:
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated.

Process Termination
A process terminates when it finishes executing its final statement and asks the operating
system to delete it by using the exit () system call. At that point, the process may return a
status value (typically an integer) to its parent process (via the wait () system call). All
the resources of the process—including physical and virtual memory, open files, and I/O
buffers—are deallocated by the operating system.

A parent may terminate the execution of one of its children for a variety of
reasons, such as these:
• The child has exceeded its usage of some of the resources that it has been
allocated. (To determine whether this has occurred, the parent must have a
mechanism to inspect the state of its children.)
• The task assigned to the child is no longer required.
• The parent is exiting, and the operating system does not allow a child to continue if
its parent terminates.
Some systems do not allow a child to exist if its parent has terminated. In such systems, if
a process terminates (either normally or abnormally), then all its children must also be
terminated. This phenomenon, referred to as cascading termination, is normally
initiated by the operating system. A process that has terminated, but whose parent has
not yet called wait (), is known as a zombie process. All processes transition to this state
when they terminate, but generally they exist as zombies only briefly.

Difference between Zombie, Orphan and Daemon Processes


1. Zombie Process:
A Zombie is a process that has completed its task but still, it shows an entry in a
process table. The zombie process usually occurred in the child process. Very
short time the process is a zombie. After the process has completed all of its
tasks it reports the parent process that it has about to terminate.
Zombie process state

Zombie is unable to terminate itself because it is treated as a dead process. So, parent
process needs to execute to terminate the command to terminate the child.is

2.OrphanProcess:
A child process that remains running even after its parent process is terminated or
completed without waiting for the child process execution is called an orphan. A
process becomes an orphan unintentionally. Sometime intentionally becomes orphans
due to long-running time to complete the assigned task without user attention. The
orphan process has controlling terminals.

3.Daemonprocess:
Daemon processes are started working when the system will be bootstrapped and
terminate only when the system is shutdown. It does not have a controlling terminal. It
always runs in the background.

Difference between Zombie, Orphan, and daemon Processes:

S.No Zombie Process Orphan Process Daemon Process


A Zombie is a process A child process that remains A daemon process is
1. that has completed its running even after its parent a system-related
task but still, it shows process is terminated or process always
an entry in a process completed without waiting for the running in the
table. child process execution is called an background.
orphan.
Zombie process states The orphan process was created Daemon process
2. always indicated by Z unknowingly due to a system state indicated by? in
crash. the field of tty
column in the output
The zombie process Orphan The zombie process has The daemon process
3. has controlling controlling terminals. does not have
terminals controlling
terminals.
The zombie process An orphan process is a computer A program that runs
4. treated as dead they process even after their parent for a long time
are not used for terminates init is become a parent makes them as a
system processing and continue the remaining task. daemon process and
runs it in the
background.
To remove the zombie Terminate the Orphan process use Daemon process
5. process, execute the the SIGHUP signal. only when system
kill command. shutdown.

1.10 Process Scheduling


The objective of multiprogramming is to have some process running at all times, to
maximize CPU utilization. The objective of time sharing is to switch the CPU among
processes so frequently that users can interact with each program while it is running. To
meet these objectives, the process scheduler selects an available process (possibly from
a set of several available processes) for program execution on the CPU. For a single-
processor system, there will never be more than one running process. If there are more
processes, the rest will have to wait until the CPU is free and can be rescheduled.
Scheduling Queues
As processes enter the system, they are put into a job queue, which consists of all
processes in the system. The processes that are residing in main memory and are ready
and waiting to execute are kept on a list called the ready queue. This queue is generally
stored as a linked list. A ready-queue header contains pointers to the first and final PCBs
in the list. Each PCB includes a pointer field that points to the next PCB in the ready
queue. The list of processes waiting for a particular I/O device is called a device queue.

A common representation of process scheduling is a queuing diagram, such as


that in Figure 3.6. Each rectangular box represents a queue. Two types of queues are
present: the ready queue and a set of device queues. The circles represent the resources
that serve the queues, and the arrows indicate the flow of processes in the system.

A new process is initially put in the ready queue. It waits there until it is selected
for execution, or dispatched. Once the process is allocated the CPU and is executing, one
of several events could occur:
• The process could issue an I/O request and then be placed in an I/O queue.
• The process could create a new child process and wait for the child’s termination.
• The process could be removed forcibly from the CPU, as a result of an interrupt, and be
put back in the ready queue.
Schedulers
A process migrates among the various scheduling queues throughout its lifetime. The
operating system must select, for scheduling purposes, processes from these queues in
some fashion. The selection process is carried out by the appropriate scheduler.

Often, in a batch system, more processes are submitted than can be executed
immediately. These processes are spooled to a mass-storage device (typically a disk),
where they are kept for later execution. The long-term scheduler, or job scheduler,
selects processes from this pool and loads them into memory for execution. The short-
term scheduler, or CPU scheduler, selects from among the processes that are ready to
execute and allocates the CPU to one of them. The long-term scheduler executes much
less frequently; minutes may separate the creation of one new process and the next. The
long-term scheduler controls the degree of multiprogramming (the number of
processes in memory).

It is important that the long-term scheduler make a careful selection. In general,


most processes can be described as either I/O bound or CPU bound. An I/O-bound
process is one that spends more of its time doing I/O than it spends doing computations.
A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its
time doing computations. It is important that the long-term scheduler select a good
process mix of I/O-bound and CPU-bound processes. The system with the best
performance will thus have a combination of CPU-bound and I/O-bound processes.
Context Switch
Interrupts cause the operating system to change a CPU from its current task and to run a
kernel routine. Such operations happen frequently on general-purpose systems. When an
interrupt occurs, the system needs to save the current context of the process running on
the CPU so that it can restore that context when its processing is done, essentially
suspending the process and then resuming it.
Switching the CPU to another process requires performing a state save of the
current process and a state restore of a different process. This task is known as a context
switch. When a context switch occurs, the kernel saves the context of the old process in
its PCB and loads the saved context of the new process scheduled to run. Context-switch
times are highly dependent on hardware support.
IMPORTANT QUESTIONS

• Explain the memory hierarchy with its neat diagram


• Compare symmetric and Asymmetric multi-processing systems. Explain
symmetric multi-processing architecture in detail
• How memory is allocated by operating for multi programs? Draw its diagram
• Operating system does different functions in user mode and kernel mode. Justify
your answer with diagram
• What is CPU scheduling? List the activities of process management
• List the following activities done by the operating systems
• File management
• Mass storage management
• List the various services provided by an operating system and explain how each of
these creates convenience for users.
• What is a system call? illustrate about any three types of system calls with its
operations.
• Discuss about how the system calls taken care by OS, with some examples give the
types of system calls, parameter passing to system calls.
• What is a system program? How many types it is divided? Discuss in detail.
• Explain different Operating System Types in detail.
• Explain operations of Operating System in detail.
• Write short note on Distributed Systems
UNIT II

Process Synchronization: IPC- Pipes, Message Passing and Shared Memory. Concept
of Synchronization, Critical section problem, Peterson’s solution, Semaphores,
Classic problems of Synchronization-The Bounded Buffer Problem, The Readers–
Writers Problem, Dining - Philosophers Problem.

You might also like