0% found this document useful (0 votes)
20 views

OS UNIX&Linux Study Material E-Notes All-Units-1

The document discusses the functions and services provided by an operating system. It describes an operating system as software that manages computer hardware resources and provides services to other programs. An operating system abstracts the underlying hardware and presents resources like memory, processors, and I/O devices in a simpler interface. It also manages these shared resources, allocating time and space on the computer system between multiple programs and users. The main functions of an operating system are to provide an interface between hardware and software, manage system resources, and enable program development and execution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

OS UNIX&Linux Study Material E-Notes All-Units-1

The document discusses the functions and services provided by an operating system. It describes an operating system as software that manages computer hardware resources and provides services to other programs. An operating system abstracts the underlying hardware and presents resources like memory, processors, and I/O devices in a simpler interface. It also manages these shared resources, allocating time and space on the computer system between multiple programs and users. The main functions of an operating system are to provide an interface between hardware and software, manage system resources, and enable program development and execution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 155

1 - Process

No. Topics Details


1. Introduction
 Meaning of OS
 Functions of OS
 OS Types
 Introduction of OS process
 Process State Transition Diagram
 Process Scheduling Non
Preemptive Preemptive
 FCFS o SJN and Round Robin
algorithms
 Physical Memory and Virtual
Memory
 Memory Allocation
Contiguous Memory
Allocation
Noncontiguous Memory
Allocation
 Paging

&p1
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

(1)What is operating System? Explain the abstract view of the components of a computer
system.
 An operating system (OS) is a collection of software that manages computer hardware
resources and provides various services for computer programs. It acts as an
intermediary between the user of a computer and the computer hardware.

 Os is one kind of system software which is directly interact with hardware device and
end user application program

Figure 1-1. A computer system consists of hardware, system programs, and application
programs.
 The placement of the operating system is shown in Fig. 1-1. At the bottom is the
hardware, which, consists of integrated circuit chips, wires, disks, a key board, a monitor
and similar physical devices.
 On the top of the hardware is the software.(1.system software 2.application software )
 Operating system runs on the hardware and it provides base for the rest of the
software.
 Most computers have two modes of operation: kernel mode and user mode.
 The operating system is the most fundamental piece of software and runs in kernel
mode.
 In this mode it has complete access to all the hardware and can execute any instruction
that the machine is capable of executing
 The rest of the software runs in user mode, in which only a subset of the machine
instructions is available. Here we find the command interpreter (shell), compilers,
editors, and other system programs.
 Finally, above the system programs are the application programs. These programs are
purchased or written by the users to solve their particular problems, such as word
processing, spreadsheets, web browser or music play To hide complexity of hardware.

&p2
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
Function of operating system
Operating systems perform two basically unrelated functions: providing a clean abstract set
of resources instead of the messy hardware to application programmers and managing
these hardware resources.
(1) Give the view of OS as an extended machine (Operating System as an Extended Machine)
 The architecture (instruction set, memory, I/O, and bus structure) of most computers at
the machine level language is primitive and awkward to program, especially for input /
output operations.
 The major task is to convert human readable form in to machine level language vice
versa
 Users do not want to be involved in programming of storage devices and such kind of converter.
 Operating System provides a set of basic commands or instructions to perform various
operations such as read, write, modify, save or close.
 Dealing with them is easier than directly dealing with hardware.
 To deal with such complexity, system program is available known as system call the task
of system call is to accepts command from user’s application software and generate
interrupt for the os
 Thus, Operating System hides the complexity of hardware and presents a beautiful
interface to the users.

System call

Figure 1-2. Operating Systems turn ugly hardware into beautiful abstractions.
 Just as the operating system shields (protect from an unpleasant experience) the
&p3
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 programmer from the disk hardware and presents a simple file-oriented interface, it
also conceals a lot of unpleasant business concerning interrupts, timers, memory
management, and other low level features.
 In each case, the abstraction offered by the operating system is simpler and easier to
use than that offered by the underlying hardware.
 In this view, the function of the operating system is to present the user with the
equivalent of an extended machine or virtual machine that is easier to work with than
the underlying hardware.
 The operating system provides a variety of services that programs can obtain using
special instructions called system calls.

(2) Give the view of OS as a Resource Manager.


 The concept of an operating system as providing abstractions to application programs is
a top down view.
 Alternatively, bottom up view holds that the OS is there to manage all pieces of a
complex system.
 A computer consists of a set of resources such as processors, memories, timers, disks,
printers and many others.
 The Operating System manages these resources and allocates them to specific
programs.
 As a resource manager, Operating system provides controlled allocation of the
processors, memories, I/O devices among various programs.
 Multiple user programs are running at the same time.
 The processor itself is a resource and the Operating System decides how much
processor time should be given for the execution of a particular user program.
 Operating system also manages memory and I/O devices when multiple users are
working.
 The primary task of OS is to keep the track of which programs are using which
resources, to grant resource requests, to account for usage, and to resolve conflicting
requests from different programs and users.
 An Operating System is a control program. A control program controls the execution of
user programs to prevent errors and improper use of computer.
 Resource management includes multiplexing (sharing) resources in two ways: in time
and in space.
&p4
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
Time multiplexing
 When a resource is time multiplexed, different programs or users take turns using it.
First one of them gets to use the resource, then another, and so on the algorithm known
as time multiplexing.
 For example, CPU and printer are time multiplexed resources. OS decides who will use it
and for how long.
Space multiplexing
 The other kind of multiplexing is space multiplexing, instead of the customers taking
turns, each one gets part of the resource the algorithm known as space multiplexing.
 For example, both primary and secondary memories are space multiplexed. OS
allocates them to user programs and keeps the track of it.

(3) Explain different types of tasks done by OS. OR


Write different services provided by operating system.
 Operating system services and facilities can be grouped into following areas:
Program development
 Operating system provides editors and debuggers to assist (help) the programmer
in creating programs.
 Usually these services are in the form of utility programs and not strictly part of
core operating system. They are supplied with operating system and referred as
application program development tools.
Program execution
 A number of tasks need to be performed to execute a program, such as instructions
and data must be loaded into main memory. I/O devices and files must be
initialized.
 The operating system handles these scheduling duties for the user.
Access to I/O devices
 Each I/O devices requires its own set of instruction for operations.
 Operating system provides a uniform interface that hides these details, so the
programmer can access such devices using simple reads and writes.
Memory Management
 Operating System manages memory hierarchy.

&p5
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 It keeps the track of which parts of memory are in use and free memory.
 It allocates the memory to programs when they need it.
 It de-allocates the memory when programs finish execution.

Controlled access to file


 In the case of file access, operating system provides a directory hierarchy for easy
access and management of files.
 OS provides various file handling commands using which users can easily read,
write, and modify files.
 In case of system with multiple users, the operating system may provide protection
mechanism to control access to file.
System access
 In case of public systems, the operating system controls access to the system as a
whole.
 The access function must provide protection of resources and data from
unauthorized users.
Error detection and response
 Various types of errors can occur while a computer system is running, which
includes internal and external hardware errors. For example, memory error, device
failure error and software errors as arithmetic overflow.
 In case, operating system must provide a response that clears error condition with
least impact on running applications.
Accounting
 A good operating system collects usage for various resources and monitor
performance parameters.
 On any system, this information is useful in anticipating need for future
enhancements.
Protection & Security
 Operating systems provides various options for protection and security purpose.
 It allows the users to secure files from unwanted usage.
 It protects restricted memory area from unauthorized access.
 Protection involves ensuring that all access to system resources is controlled.

&p6
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
(4)Types of os

All the operating system consist of similar component and perform similar functions but the
method and procedure for performing these function are different.
Operating system classified in to different categories based on their features

(4.1)Give the features of Batch Operating System.


 Batch operating system is one that processes routine jobs without any interactive user
presents. Such as claim processing in insurance and sales reporting etc.
 To improve utilization, the concept of batch operating system was developed.
 The batch operating system place the users job on a input queue and these jobs are stored as batch
 A batch is sequence of users job
 Jobs with similar needs were batched together and were run through the computer as
a group.
 The primary function of batch processing system is to implement the processing of job
in batch without requiring any intervention of the operator
 It is the task of the batch monitor to execute all jobs at define interval of time
 The batch monitor accept the commands for initialization, processing and termination
of batch it execute the next job in sequence
 The part of the memory occupied by the batch monitor is called system area and the
part occupied by the user is known as user area.
 The scheduling is based on FCFS algorithm
 With the use of this type of operating system, the user no longer has direct access to
machine.

cpu

• advance inputs
Batch- • cpu+memory=100 memory

1
• advance inputs
Batch- • nic+memory=40
storage

&p7
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 Advantages:
 Move much of the work of the operator to the computer.
 Increase performance since it was possible for job to start as soon as the
previous job finished.
 Disadvantages:
 Large Turnaround time.
 More difficult to debug program.
 Due to lack of protection scheme one batch job can affect pending jobs.

(4.2)Explain the features of Time Sharing System.


 Time Sharing is a logical extension of multiprogramming.
 Multiple jobs are executed simultaneously by switching the CPU back and forth among
them.
 The switching occurs so frequently (speedy) that the users cannot identify the presence
of other users or programs.
 Users can interact with his program while it is running in timesharing mode.
 Processor’s time is shared among multiple users. An interactive or hands on computer
system provides online communication between the user and the system.
 A time shared operating system uses CPU scheduling and multiprogramming to provide
each user with a small portion of a time shared computer. Each user has at least one
separate program in memory.
 A time shared operating system allows many users to share computer simultaneously.
Since each action or command in a time shared system tends to be short, only a little
CPU time is needed for each user.
 The time known as time slice or cpu quantum

&p8
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 Advantages :-
 Easy to use
 User friendly
 Quick response time

 Disadvantages:-
 If any problem affects the OS, you may lose all the contents which have stored
already
Unwanted user can use your own system in case if proper security options are not available

(4.3)Explain the features of Multiprogramming Operating System:

 Multiprogramming is technique to execute number of program simuntensiouly by


single cpu

 In multiprogramming number of process in main memory


 The os picks and begin to execute one of the job in main memory
 If any input output happens in process then cpu switch to another job it is called
multiprogramming
&p9
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 The os allows multiple jobs to execute multiple job in single cpu

 Advantages

 Cpu is not ideal at any time


 Efficient memory utilization
 Throuput put time is increase

(4.4)Explain the features of Real Time Operating System.


 A real time operating system is used, when there are rigid (strict) time requirements on
the operation of a processor or the flow of data.
 It is often used as a control device in a dedicated application. Systems that control
scientific experiments, medical imaging systems, and industrial control system are real
time systems. These applications also include some home appliance system, weapon
systems, and automobile engine fuel injection systems.
 Real time Operating System has well defined, fixed time constraints. Processing must be
done within defined constraints or the system will fail.
 Since meeting strict deadlines is crucial in real time systems, sometimes an operating is
simply a library linked in with the application programs.
 There are two types of real time operating system,
 Hard real system:
 This system guarantees that critical tasks complete on time.
 Many of these are found in industrial process control, avionics, and military
and similar application areas.
 This goal says that all delays in the system must be restricted.
 Soft real system:
 In soft real-time system, missing an occasional deadline, while not desirable,
is acceptable and does not cause any permanent damage.
 Digital audio or multimedia systems fall in this category.
 An example of real time system is e-Cos.

&p10
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

Process
(1) What is Process? Give the difference between Process and Program.
Process:
 Process is a program under execution.

 It is an instance of an executing program, including the current values of the pro-
gram counter, registers & variables.
 Process is an abstraction of a running program.
 Process is start when cpu allocate to program 
 There are many resources are required to create process such as memory , cpu ,i/o files 
 Once a program is in the process there are many operation done on it like delete , suspend
interrupt , create and dead lock. 

Process Program
A process is program in execution. A program is set of instructions.
A process is an active/ dynamic entity. A program is a passive/ static entity.
A process has a limited life span. It is A program has a longer life span. It is
created when execution starts and stored on disk forever.
terminated as execution is finished.
A process contains various resources A program is stored on disk in some file.
like memory address, disk, printer It does not contain any other resource.
etc… as per requirements.
A process contains memory address A program requires memory space on
which is called address space. disk to store all instructions.

(2) Explain Process Control Block (PCB).


PCB (Process Control Block):
 To implement the process model, the operating system maintains a table (an array
of structures) called the process table, with one entry per process, these entries
are known as Process Control Block.
 Process table contains the information what the operating system must know to 
 manage and control process switching, including the process location and process
attributes.
&p11
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 Each process contains some more information other than its address space. This in-
formation is stored in PCB as a collection of various fields. Operating system main-
tains the information to manage process. 

   
 Various fields and information stored in PCB are given as below:
 Process Id: Each process is given Id number at the time of creation.
 Priority : it comes in number lesser number has high priority.
 Process state: The state may be ready, running, and blocked.
 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 com-
puter 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.
 CPU-scheduling(event) information: This information includes a process
priority, point- ers to scheduling queues, and any other scheduling parameters.
 Memory-management information: This information may include such infor-
mation as the value of the base and limit registers, the page tables, or the seg-
ment tables, depending on the memory system used by the operating system.
 Accounting information(resource held): This information includes the amount
of CPU and real time used, time limits, account numbers, job or process
numbers, and so on.
 Status information(Pcb pointer): The information includes the list of I/O devices
allocated to this process, a list of open files, and so on.the pcb pointer point to
the next pcb in sequence

&p12
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

(3)PSTD (Process state transition diagram ):


 PSTD indicate the current nature of the process it display information about the
active process those are scheduled.
 When user is assign program to the system os generate PCB for that job basis on the
policy process are passed in to PSTD with different five state known as process state
transition diagram.

NEW (HOLD) STATE:


 Any process submited to the system it enter in new state job scheduler select the
job basis on the predetrmine policy and send it to ready state.

READY STATE:
 In this state process are ready to get excute , reside in main memory and wait for
theprocessor 

RUNNING STATE:
 Process shceduler select the job basis on the algorithem and send it to the
processor there are different types of algorithem as per the os.

WAITING STATE:
 During the execuation of process any input is require then it send to the waiting
state and then ready state.if timer interrupt arise then it directly send to ready
state.

TERMINATED(FINISH) STATE:
 Process shceduler terminate the process. It may be many situation like finish the
process,delete etc.

&p13
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

(4)What is scheduler? Explain queuing diagram representation of process scheduler with


figure.
Scheduler:
 A program or a part of operating system that arranges jobs or a computer's
operations into an appropriate sequence is called scheduler.

Figure 3-6 A Queuing diagram representation of process scheduler

&p14
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

 As processes enter the system, they are put into a job queue (batch jobs), 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 and wait there until it is selected
for execution or dispatched.
 The process therefore may have to wait for the disk. The list of processes waiting for
a particular I/O device is called a device queue. Each device has its own device
queue.
 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 sub process and wait for the sub process'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.
Scheduler
 Schedulers are special system software which handles process scheduling in various
ways.
 Their main task is to select the jobs to be submitted into the system and to decide
which process to run.
 Schedulers are of three types:
1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
Long Term Scheduler
 It is also called job scheduler.
 Long term scheduler determines which programs are admitted to the system for
processing.
 Job scheduler selects processes from the queue and loads them into memory for
execution.
 Process loads into the memory for CPU scheduling. The primary objective of the job
scheduler is to provide a balanced mix of jobs, such as I/O bound and processor
bound.
 It also controls the degree of multiprogramming.
&p15
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
 If the degree of multiprogramming is stable, then the average rate of process
creation must be equal to the average departure rate of processes leaving the
system.
 On some systems, the long term scheduler may not be available or minimal.
 Time-sharing operating systems have no long term scheduler.
 When process changes the state from new to ready, then there is use of long term
scheduler.
Short Term Scheduler
 It is also called CPU scheduler.
 Main objective is increasing system performance in accordance with the chosen set
of criteria.
 It is the change of ready state to running state of the process.
 CPU scheduler selects process among the processes that are ready to execute and
allocates CPU to one of them.
 Short term scheduler also known as dispatcher, execute most frequently and makes
the fine grained decision of which process to execute next.
 Short term scheduler is faster than long term scheduler.
Medium Term Scheduler
 Medium term scheduling is part of the swapping.
 It removes the processes from the memory.
 It reduces the degree of multiprogramming.
 Running process may become suspended if it makes an I/O request.
 Suspended processes cannot make any progress towards completion.
 In this condition, to remove the process from memory and make space for other
process, the suspended process is moved to the secondary storage.
 This process is called swapping, and the process is said to be swapped out or rolled
out.
 Swapping may be necessary to improve the process mix. e of handling the swapped
out-processes.

&p16
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
(5)What is scheduling algorithm, Types of algorithm? How it is handled a process?
 Basis on the algorithm which process execute first and which process execute last there are
two types of algorithm.

 Preemptive scheduling algorithm:


 Preemptive Scheduling is a CPU scheduling technique that works by dividing time slots of
CPU to a given process. The time slot given might be able to complete the whole process or
might not be able to it.
 Currently running process may be interrupted by os and put into ready state 
 Time interrupt is done then context switches is occurs 
In preemptive scheduling algorithm running process may be interrupted by high
priority process with low priority process.
 Non Preemptive scheduling algorithm:
 in non-preemptive scheduling, any new process has to wait until the running process
finishes its CPU cycle.
 A non preemptive scheduling it process scheduled request to completion state
In non –preemptive scheduling cpu transfer one job to another when first job gets
complete
 The list of pending request never contain preempted request 

(5.1)What is interrupt? How it is handled by an OS?


 A software interrupt is caused either by an exceptional condition in the processor it-
self, or a special instruction in the instruction set which causes an interrupt when it
is executed.
 The former is often called a trap or exception and is used for errors or events occur-
ring during program execution that is exceptional enough that they cannot be han--
dled within the program itself.
 Interrupts are a commonly used technique for process switching.
 Two types of interrupts timer interrupt and priority interrupt 
 Associated with each I/O device class (e.g., floppy disks, hard disks etc…) there is a
location (often near the bottom of memory) called the interrupt vector.
 It contains the address of the interrupt service procedure.
 Suppose that user process 3 is running when a disk interrupt occurs.
 User process 3’s program counter, program status word, and possibly one or more
registers are pushed onto the (current) stack by the interrupt hardware.
 The computer then jumps to the address specified in the disk interrupt vector.
 That is all the hardware does.
&p17
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process
(5.2)What is context switching?
 Switching the CPU to another process requires saving the state of the old process and
loading the saved state for the new process.
 This task is known as a context switch.
 The context of a process is represented in the PCB of a process; it includes the value of
the CPU registers, the process state and memory-management information.
 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 time is pure overhead, because the system does no useful work while
switching.
 Its speed varies from machine to machine, depending on the memory speed, the num-
ber of registers that must be copied, and the existence of special instructions.

Figure 2-1. Context Switching

&p18
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
1 - Process

(5.3)Define following terms:


Race Condition
 Race condition can be defined as situation where two or more processes are reading
or writing some shared data and the final result depends on who runs precisely
when (their relative execution order).
Mutual Exclusion
 It is a way of making sure that if one process is using a shared variable or file; the
other process will be excluded (stopped) from doing the same thing.
Turnaround Time
 Time required to complete execution of process is known as turnaround time.
 Turnaround time = Process finish time – Process arrival time.
Throughput
 Number of processes completed per time unit is called throughput.
Critical Section
 The part of program or code of segment of a process where the shared resource is
accessed is called critical section.
Waiting time
 It is total time duration spent by a process waiting in ready queue.
 Waiting time = Turnaround time – Actual execution time.
Response Time
It is the time between issuing a command/request and getting output/result


&p19
Haresh Khachariya, CS&IT nt | Operating System (2020-21)
Process Scheduling

(11) Explain FCFS, Round Robin, Shortest Job First, Shortest Remaining Job First and Priority
Scheduling algorithms with illustration.
I FCFS (First Come First Serve):
 Selection criteria :
The process that request first is served first. It means that processes are served in the
exact order of their arrival.
 Decision Mode :
Non preemptive: Once a process is selected, it runs until it is blocked for an I/O or
some event, or it is terminated.
 Implementation:
This strategy can be easily implemented by using FIFO queue, FIFO means First In First
Out. When CPU becomes free, a process from the first position in a queue is selected
to run.
 Example :
Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in following table. Consider all time values in
milliseconds.

Process Arrival Time (T0) Time required for completion (∆T)


(CPU Burst Time)
P0 0 10
P1 1 6

P2 3 2
P3 5 4

 Gantt Chart :
P0 P1 P2 P3

0 10 16 18 22
 Initially only process P0 is present and it is allowed to run. But, when P0 completes,
all other processes are present. So, next process P1 from ready queue is selected and

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling
allowed to run till it completes. This procedure is repeated till all processes completed
their execution.
 Statistics :

Process Arrival CPU Burst Finish Time Turnaround Time Waiting Time
Time (T0) Time (∆T) (T1) (TAT=T1-T0) (WT=TAT-∆T)
P0 0 10 10 10 0

P1 1 6 16 15 9
P2 3 2 18 15 13

P3 5 4 22 17 13

Average Turnaround Time: (10+15+15+17)/4 = 57/4 = 14.25 ms.


Average Waiting Time: (0+9+13+13)/4 = 35/4 = 8.75 ms.

 Advantages:
 Simple, fair, no starvation.
 Easy to understand, easy to implement.
 Disadvantages :
 Not efficient. Average waiting time is too high.
 Convoy effect is possible. All small I/O bound processes wait for one big CPU
bound process to acquire CPU.
 CPU utilization may be less efficient especially when a CPU bound process is
running with many I/O bound processes.

II Shortest Job First (SJF):


 Selection Criteria :
The process, that requires shortest time to complete execution, is served first.
 Decision Mode :
Non preemptive: Once a process is selected, it runs until either it is blocked for an I/O
or some event, or it is terminated.
 Implementation :

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling
This strategy can be implemented by using sorted FIFO queue. All processes in a
queue are sorted in ascending order based on their required CPU bursts. When CPU
becomes free, a process from the first position in a queue is selected to run.
 Example :
Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in following table. Consider all time values in
milliseconds.

Process Arrival Time Time required for completion (∆T)


(T0) (CPU Burst Time)
P0 0 10
P1 1 6
P2 3 2

P3 5 4

 Gantt Chart :
P0 P2 P3 P1
0 10 12 16 22
 Initially only process P0 is present and it is allowed to run. But, when P0 completes,
all other processes are present. So, process with shortest CPU burst P2 is selected and
allowed to run till it completes. Whenever more than one process is available, such
type of decision is taken. This procedure us repeated till all process complete their
execution.

 Statistics :
Process Arrival Time CPU Burst Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (Wt=TAT-∆T)

P0 0 10 10 10 0

P1 1 6 22 21 15
P2 3 2 12 9 7

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

P3 5 4 16 11 7

Average Turnaround Time: (10+21+9+11)/4 = 51/4 = 12.75 ms.


Average Waiting Time: (0+15+7+7) / 4 = 29 / 4 = 7.25 ms.
 Advantages:
 Less waiting time.
 Good response for short processes.
 Disadvantages :
 It is difficult to estimate time required to complete execution.
 Starvation is possible for long process. Long process may wait forever.

III Shortest Remaining Time Next (SRTN):


 Selection criteria :
The process, whose remaining run time is shortest, is served first. This is a preemptive
version of SJF scheduling.
 Decision Mode:
Preemptive: When a new process arrives, its total time is compared to the current
process remaining run time. If the new job needs less time to finish than the current
process, the current process is suspended and the new job is started.
 Implementation :
This strategy can also be implemented by using sorted FIFO queue. All processes in a
queue are sorted in ascending order on their remaining run time. When CPU becomes
free, a process from the first position in a queue is selected to run.
 Example :
Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in following table. Consider all time values in
milliseconds.
Process Arrival Time (T0) Time required for completion (∆T)
(CPU Burst Time)
P0 0 10

P1 1 6

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

P2 3 2

P3 5 4
 Gantt Chart :

P0 P1 P2 P1 P3 P0
0 1 3 5 9 13 22
 Initially only process P0 is present and it is allowed to run. But, when P1 comes, it has shortest
remaining run time. So, P0 is preempted and P1 is allowed to run. Whenever new process
comes or current process blocks, such type of decision is taken. This procedure is repeated
till all processes complete their execution.

 Statistics :

Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (WT=TAT-∆T)

P0 0 10 22 22 12
P1 1 6 9 8 2
P2 3 2 5 2 0
P3 5 4 13 8 4

Average Turnaround Time: (22+8+2+8) / 4 = 40/4 = 10 ms.


Average Waiting Time: (12+2+0+4)/4 = 18 / 4 = 4.5 ms.

 Advantages :
 Less waiting time.
 Quite good response for short processes.
 Disadvantages :
 Again it is difficult to estimate remaining time necessary to complete execution.
 Starvation is possible for long process. Long process may wait forever.
 Context switch overhead is there.

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

IV Round Robin:
 Selection Criteria:
 Each selected process is assigned a time interval, called time quantum or time slice.
Process is allowed to run only for this time interval. Here, two things are possible:
First, Process is either blocked or terminated before the quantum has elapsed. In this
case the CPU switching is done and another process is scheduled to run. Second,
Process needs CPU burst longer than time quantum. In this case, process is running
at the end of the time quantum. Now, it will be preempted and moved to the end of
the queue. CPU will be allocated to another process. Here, length of time quantum is
critical to determine.
 Decision Mode:
Preemptive:
 Implementation :
This strategy can be implemented by using circular FIFO queue. If any process comes,
or process releases CPU, or process is preempted. It is moved to the end of the queue.
When CPU becomes free, a process from the first position in a queue is selected to
run.
 Example :
Consider the following set of four processes. Their arrival time and time required to
complete the execution are given in the following table. All time values are in
milliseconds. Consider that time quantum is of 4 ms, and context switch overhead is
of 1 ms.

Process Arrival Time (T0) Time required for completion (∆T)

P0 0 10

P1 1 6
P2 3 2
P3 5 4

 Gantt Chart :
P0 P1 P2 P0 P3 P1 P0

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

0 4 5 9 10 12 13 17 18 22 23 25 26 28
 At 4ms, process P0 completes its time quantum. So it preempted and another process
P1 is allowed to run. At 12 ms, process P2 voluntarily releases CPU, and another
process is selected to run. 1 ms is wasted on each context switch as overhead. This
procedure is repeated till all process completes their execution.

 Statistics:

Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (WT=TAT-∆T)

P0 0 10 28 28 18
P1 1 6 25 24 18
P2 3 2 12 9 7

P3 5 4 22 17 13

Average Turnaround Time: (28+24+9+17)/4 = 78 / 4 = 19.5 ms


Average Waiting Time: (18+18+7+13)/4 = 56 / 4 = 14 ms

 Advantages:
 One of the oldest, simplest, fairest and most widely used algorithms.
 Disadvantages:
 Context switch overhead is there.
 Determination of time quantum is too critical. If it is too short, it causes frequent context
switches and lowers CPU efficiency. If it is too long, it causes poor response for short
interactive process.

V Non Preemptive Priority Scheduling:


 Selection criteria :
The process, that has highest priority, is served first.
 Decision Mode:
Non Preemptive: Once a process is selected, it runs until it blocks for an I/O or some
event, or it terminates.

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling
 Implementation :
This strategy can be implemented by using sorted FIFO queue. All processes in a
queue are sorted based on their priority with highest priority process at front end.
When CPU becomes free, a process from the first position in a queue is selected to
run.
 Example :
Consider the following set of four processes. Their arrival time, total time required
completing the execution and priorities are given in following table. Consider all time
values in millisecond and small values for priority means higher priority of a process.
Process Arrival Time (T0) Time required for completion ( ∆T) Priority
P0 0 10 5
P1 1 6 4
P2 3 2 2

P3 5 4 0

Here, process priorities are in this order: P3 > P2 > P1 > P0.
 Gantt Chart :

P0 P3 P2 P1
0 10 14 16 22
 Initially only process P0 is present and it is allowed to run. But, when P0 completes, all other
processes are present. So, process with highest priority P3 is selected and allowed to run till
it completes. This procedure is repeated till all processes complete their execution.
 Statistics :

Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)
P0 0 10 10 10 0
P1 1 6 22 21 15
P2 3 2 16 13 11

P3 5 4 14 9 5

Average Turnaround Time: (10+21+13+9) / 4 = 53 / 4 = 13.25 ms

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

Average Waiting Time: (0+15+11+5) / 4 = 31 / 4 = 7.75 ms


 Advantages:
 Priority is considered. Critical processes can get even better response time.
 Disadvantages:
 Starvation is possible for low priority processes. It can be overcome by using
technique called ‘Aging’.
 Aging: gradually increases the priority of processes that wait in the system for a
long time.

Preemptive Priority Scheduling:


 Selection criteria :
The process, that has highest priority, is served first.
 Decision Mode:
Preemptive: When a new process arrives, its priority is compared with current
process priority. If the new job has higher priority than the current, the current
process is suspended and new job is started.
 Implementation :
This strategy can be implemented by using sorted FIFO queue. All processes in a
queue are sorted based on priority with highest priority process at front end. When
CPU becomes free, a process from the first position in a queue is selected to run.
 Example :
Consider the following set of four processes. Their arrival time, time required
completing the execution and priorities are given in following table. Consider all time
values in milliseconds and small value of priority means higher priority of the process.

Process Arrival Time (T0) Time required for completion ( ∆T) Priority
P0 0 10 5
P1 1 6 4
P2 3 2 2
P3 5 4 0

Here process priorities are in this order: P3>P2>P1>P0

Haresh Khachariya CS&IT| Operating System (2020-21)


Process Scheduling

 Gantt chart:
P0 P1 P2 P3 P1 P0
0 1 3 5 9 13 22
 Initially only process P0 is present and it is allowed to run. But when P1 comes, it has higher
priority. So, P0 is preempted and P1 is allowed to run. This process is repeated till all processes
complete their execution.

 Statistics:

Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)
P0 0 10 22 22 12
P1 1 6 13 12 6
P2 3 2 5 2 0
P3 5 4 9 4 0

Average Turnaround Time: (22+12+2+4) / 4 = 40 / 4 = 10 ms


Average Waiting Time: (12+6+0+0) / 4 = 18 / 4 = 4.5 ms

 Advantages:
 Priority is considered. Critical processes can get even better response time.
 Disadvantages:
 Starvation is possible for low priority processes. It can be overcome by using
technique called ‘Aging’.
 Aging: gradually increases the priority of processes that wait in the system for a
long time.
 Context switch overhead is there.

Haresh Khachariya ,Dept:CS&IT |– Operating System (2020-21)


Process Scheduling

(2) Five batch jobs A to E arrive at same time. They have estimated running times 10,6,2,4 and 8
minutes. Their priorities are 3,5,2,1 and 4 respectively with 5 being highest priority. For each
of the following algorithm determine mean process turnaround time. Ignore process swapping
overhead.
Round Robin, Priority Scheduling, FCFS, SJF.

Process Running Time Priority


Time required for completion ( ∆T)
A 10 3
B 6 5

C 2 2
D 4 1
E 8 4

First Come First Served:

A B C D E
0 10 16 18 22 30
Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)
A 0 10 10 10 0
B 0 6 16 16 10

C 0 2 18 18 16
D 0 4 22 22 18

E 0 8 30 30 22

Average Turnaround Time: (10+16+18+22+30) / 5 = 96 / 5 = 19.2 ms


Average Waiting Time: (0+10+16+18+22) / 5 = 56 / 5 = 13.2 ms

Haresh Khachariya ,Dept:CS&IT |– Operating System (2020-21)


Process Scheduling

Shortest Job First:

C D B E A
0 2 6 12 20 30
Process Arrival Completion Finish Time Turnaround Time Waiting Time
time (T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)

A 0 10 30 30 20
B 0 6 12 12 6

C 0 2 2 2 0
D 0 4 6 6 2

E 0 8 20 20 12

Average Turnaround Time: (30+12+2+6+20) / 5 = 70 / 5 = 14 ms


Average Waiting Time: (20+6+0+2+12) / 5 = 40 / 5 = 8 ms

Priority:

B E A C D
0 6 14 24 26 30

Process Arrival Completion Finish Time Turnaround Time Waiting Time


time (T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)

A 0 10 24 24 14
B 0 6 6 6 0
C 0 2 26 26 24

D 0 4 30 30 26
E 0 8 14 14 6

Average Turnaround Time: (24+6+26+30+14) / 5 = 100 / 5 = 20 ms

Haresh Khachariya ,Dept:CS&IT |– Operating System (2020-21)


Process Scheduling

Average Waiting Time: (14+0+24+26+6) / 5 = 70 / 5 = 14 ms

Round Robin:
Time slice OR Quantum time= 2min.

A B C D E A B D E A B E A E A
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Process Arrival time Completion Finish Time Turnaround Time Waiting Time
(T0) Time (∆T) (T1) (TAT=T1-T0) (TAT-∆T)
A 0 10 30 30 20
B 0 6 22 22 16
C 0 2 6 6 4
D 0 4 16 16 12
E 0 8 28 28 20

Average Turnaround Time: (30+22+6+16+28) / 5 = 102 / 5 = 20.4 ms


Average Waiting Time: (20+16+4+12+20) / 5 = 72 / 5 = 14.4 ms

(3) Suppose that the following processes arrive for the execution at the times indicated. Each
process will run the listed amount of time. Assume preemptive scheduling.
Process Arrival Time (ms) Burst Time (ms)
P1 0.0 8
P2 0.4 4
P3 1.0 1
What is the turnaround time for these processes with Shortest Job First scheduling algorithm?

Haresh Khachariya ,Dept:CS&IT |– Operating System (2020-21)


Process Scheduling

(4) Consider the following set of processes with length of CPU burst time given in milliseconds.
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
Assume arrival order is: P1, P2, P3, P4, P5 all at time 0 and a smaller priority number implies a
higher priority. Draw the Gantt charts illustrating the execution of these processes using
preemptive priority scheduling.

Haresh Khachariya ,Dept:CS&IT |– Operating System (2020-21)


Memory management

(1) Compare multiprogramming with fixed partition & multiprogramming with


variable partition with diagram. OR
Explain swapping in memory management.
Swapping
 In practice total amount of memory needed by all the processes is often much more
than the available memory.
 Swapping is used to deal with memory overhead.
 Swapping consists of bringing in each process in its entirety, running it for a while,
then putting it back on the disk.
 The event of copying process from hard disk to main memory is called as Swapped-
in.
 The event of copying process from main memory to hard disk is called as Swapped-
out.
 When swapping creates multiple holes in memory, it is possible to combine them all
into one big one by moving all the processes downward as far as possible. This
technique is called as memory compaction.
 Two ways to implement Swapping System
 Multiprogramming with Fixed partitions.
 Multiprogramming with dynamic partitions.
Multiprogramming with Fixed partitions
 This method allows multiple processes to execute simultaneously.
 Here memory is divided into fixed sized partitions. Size can be equal or unequal for
different partitions.
 Generally unequal partitions are used for better utilizations.
 Each partition can accommodate exactly one process, means only single process can
be placed in one partition.
 The partition boundaries are not movable.
 Whenever any program needs to be loaded in memory, a free partition big enough
to hold the program is found. This partition will be allocated to that program or
process.
 If there is no free partition available of required size, then the process needs to
wait. Such process will be put in a queue.
 There are two ways to maintain queue
 Using multiple Input Queues.
 Using single Input Queue.
Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)
Memory management

 The disadvantage of sorting the incoming jobs into separate queues becomes
apparent when the queue for a large partition is empty but the queue for a small
partition is full, as is the case for partitions 1 and 3 in Fig. 5-1(a).
 Here small jobs have to wait to get into memory, even though plenty of memory is
free. An alternative organization is to maintain a single queue as in Fig. 5-1(b).
Whenever a partition becomes free, the job closest to the front of the queue that
fits in it could be loaded into the empty partition and run.

Partition - 4 Partition - 4
Single
Partition - 3 Input Partition - 3
Multiple
Queue
Input
Queues

Partition - 2 Partition - 2

Partition - 1 Partition - 1
Operating Operating
System System

Figure 5-1. (a) Fixed memory partitions with separate input queues for each partition.
(b) Fixed memory partitions with a single input queue.

Multiprogramming with dynamic partitions


 This method also allows multiple processes to execute simultaneously.
 Here, memory is shared among operating system and various simultaneously
running processes.
 Memory is not divided into any fixed partitions. Also the number of partitions is not
fixed. Process is allocated exactly as much memory as it requires.
 Initially, the entire available memory is treated as a single free partition.
 Whenever any process enters in a system, a chunk of free memory big enough to fit
the process is found and allocated. The remaining unoccupied space is treated as
another free partition.
 If enough free memory is not available to fit the process, process needs to wait until
required memory becomes available.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 Whenever any process gets terminate, it releases the space occupied. If the
released free space is contiguous to another free partition, both the free partitions
are merged together in to single free partition.
 Better utilization of memory than fixed sized size partition.
 This method suffers from External fragmentation.

Figure 5-2. Memory allocation changes as processes come into memory and leave it.
The shaded regions are unused memory.

(2) Explain memory management with Linked list and Bit maps.
 When memory is assigned dynamically, the operating system must manage it.
 In general there are two ways to keep track of memory usage.
 Memory Management with Bitmap.
 Memory Management with Linked List.
Memory Management with Bitmap
 With bitmap, memory is divided into allocation units.
 Corresponding to each allocation unit there is a bit in a bitmap.
 Bit is 0 if the unit is free.
 Bit is 1 if unit is occupied.
 The size of allocation unit is an important design issue, the smaller the size, the
larger the bitmap.
 The main problem is that when it has been decided to bring a k unit process, the
memory manager must search the bitmap to find a run of k consecutive 0 bits in the

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

map.
 Searching a bitmap for a run of a given length is a slow operation.
 Figure 5-3 shows part of memory and the corresponding bitmap.
Memory Management with Linked List
 Another way to keep track of memory is to maintain a linked list of allocated and
free memory segments, where segment either contains a process or is an empty
hole between two processes.
 The memory of Fig. 5-3(a) is represented in Fig. 5-3(c) as a linked list of segments.
 Each entry in the list specifies a hole (H) or process (P), the address at which it starts
the length and a pointer to the next entry.

Figure 5-3. (a) A part of memory with five processes and three holes. The tick marks
show the memory allocation units. The shaded regions (0 in the bitmap) are free. (b)
The corresponding bitmap. (c) The same information as a list.

 The segment list is kept sorted by address. Sorting this way has the advantage that
when a process terminates or is swapped out, updating the list is straightforward.
 A terminating process normally has two neighbors (except when it is at the very top
or bottom of memory).
 These may be either processes or holes, leading to the four combinations of Fig. 5-4.
In Fig. 5-4(a) updating the list requires replacing a P by an H. In Fig. 5-4(b) and Fig. 5-
4(c) two entries are merged into one, and the list becomes one entry shorter.
 In Fig. 5-4(d), three entries are merged and two items are removed from the list.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

Figure 5-4. Four neighbor combinations for the terminating process X.

(3) Given memory partition of 100K, 500K, 200K, 300K, and 600K in order, how would
each of the First-fit, Next fit, Best-fit and Worst-fit algorithms place the processes of
212K, 417K, 112K and 426K in order? Which algorithm makes the most efficient
use of memory? Show the diagram of memory status in each case.

Given memory Partition is as shown below.

100k 500k 200k 300k 600k

First Fit:
 Search Starts from the starting location of the memory.
 First available hole that is large enough to hold the process is selected for allocation.
 The hole is then broken up into two pieces, one for process and another for unused
memory.
 Search time is smaller here.
 Memory loss is higher, as very large hole may be selected for small process.
 Here process of size 426k will not get any partition for allocation.

100k 176k 200k 300k 183k


212k 112k 417k

Next Fit:

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 Next fit is minor variation of first fit algorithm.


 It works in the same way as first fit, except that it keeps the track of where it is
whenever it finds a suitable hole.
 The next time when it is called to find a hole, it starts searching the list from the
place where it left off last time.
 Search time is smaller here.
 Here process of size 426k will not get any partition for allocation.

100k 288k 200k 300k 71k


212k 417k 112k

Best Fit
 Entire memory is searched here.
 The smallest hole, which is large enough to hold the process, is selected for
allocation.
 Search time is high, as it searches entire memory.
 Memory loss is less. More sensitive to external fragmentation, as it leaves tiny holes
into which no process can fit.

100k 500k 200k 300k 600k


417k 112k 212k 426k

Worst Fit
 Entire memory is searched here also. The largest hole, which is largest enough to
hold the process, is selected for allocation.
 This algorithm can be used only with dynamic partitioning.
 Here process of size 426k will not get any partition for allocation.

100k 500k 200k 300k 276k


417k 212k 112k

Best fit algorithm gives the efficient allocation of memory.


(4) What is Virtual Memory? Explain.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 The basic idea behind virtual memory is that each program has its own address
space, which is broken up into pages.
 Each page is a contiguous range of addresses.
 These pages are mapped onto the physical memory but, to run the program, all
pages are not required to be present in the physical memory.
 The operating system keeps those parts of the program currently in use in main
memory, and the rest on the disk.
 Virtual memory works fine in a multiprogramming system, with bits and pieces of
many programs in memory at once.
 While a program is waiting for part of itself to be brought in, it is waiting for I/O and
cannot run, so the CPU can be given to another process.
 In a system using virtual memory, the physical memory is divided into page frames
and the virtual address space is divided in into equally-sized partitions called pages.

(5) What is paging? Explain the conversion of virtual address in paging with example.
Paging
 The program generated address is called as Virtual Addresses and form the Virtual
Address Space.
 Most virtual memory systems use a technique called paging.
 Virtual address space is divided into fixed-size partitions called pages.
 The corresponding units in the physical memory are called as page frames.
 The pages and page frames are always of the same size.
 Size of Virtual Address Space is greater than that of Main memory, so instead of
loading entire address space in to memory to run the process, MMU copies only
required pages into main memory.
 In order to keep the track of pages and page frames, OS maintains a data structure
called page table.
The conversion of virtual address to physical address
 When virtual memory is used, the virtual address is presented to an MMU (Memory
Management Unit) that maps the virtual addresses onto the physical memory
addresses.
 A very simple example of how this mapping works is shown in Fig. 5-6.
 In this example, we have a computer generated 16-bit addresses, from 0 up to 64K.
These are the virtual addresses.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 However, only 32 KB of physical memory is available, so although 64-KB programs


can be written, they cannot be loaded in to memory in their entirety and run.
 A complete copy of a program’s core image, up to 64 KB, must be present on the
disk. Only required pages are loaded in the physical memory.

Figure 5-5. The relation between virtual addresses and physical memory addresses is
given by the page table.

 With 64 KB of virtual address space and 32 KB of physical memory, we get 16 virtual


pages and 8 page frames.
 Transfers between RAM and disk are always in units of a page.
 The virtual address is split into a virtual page number (high order bits) and an offset
(low-order bits).
 With a 16-bit address and a 4 - KB page size, the upper 4 bits could specify one of
the 16 virtual pages and the lower 12 bits would then specify the byte offset (0 to
4095) within the selected page.
 The virtual page number is used as an index into the Page table.
 If the present/absent bit is 0, it is page-fault; a trap to the operating system is
caused to bring required page into main memory.
 If the present/absent bit is 1, required page is there with main memory and page

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

frame number found in the page table is copied to the higher order bit of the output
register along with the offset.
 Together Page frame number and offset creates physical address.
Physical Address = Page frame Number + offset of virtual address.

Figure 5-6. The internal operation of the MMU with 16 4-KB pages.

(6) Explain page table in brief. OR


Explain Structure of Page Table.
Page Table
 Page table is a data structure which translates virtual address into equivalent
physical address.
 The virtual page number is used as an index into the Page table to find the entry for
that virtual page and from the Page table physical page frame number is found.
 Thus the purpose of page table is to map virtual pages onto page frames.
 Typical fields of page table are Page frame number, Present / absent bit, Protection

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

bits, Modified field, Referenced field, Cashing disabled field etc…

Figure 5-7. A typical page table entry


 Different fields of typical page table are as below
 Page frame Number: This field shows the corresponding physical page frame
number for a particular virtual page.
 Present/Absent bit: If this bit is 1, the entry is valid and can be used, if it is 0 the
virtual page to which the entry belongs is not currently in memory. Accessing
page table entry with this bit set to 0 causes a page fault.
 The Protection bits: This tells what kind of access is permitted. In the simplest
form, this field contains 1 bit, with 0 for read/write and 1 for read only.
 Modified bit: When a page is written to, the hardware sets the modified bit. If
the page in memory has been modified, it must be written back to disk. This bit
is also called as dirty bit as it reflects the page’s state.
 Referenced bit: A references bit is set whenever a page is referenced, either for
reading or writing. Its value helps operating system in page replacement
algorithm.
 Cashing Disabled bit: This feature is important for pages that maps onto device
registers rather than memory. With this bit cashing can be turned off.

(7) Explain Following Terms.


Demand Paging
 In paging system, processes are started up with none of their pages in memory.
 When CPU tries to fetch the first instruction, it gets page fault, other page faults for
global variables and stack usually follow quickly.
 After a while, the process has most of the pages it needs in main memory and it has
few page faults.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 This strategy is called demand paging because pages are loaded only on demand,
not in advance.
Working Set
 The set of pages that a process is currently using is known as working set.
Thrashing
 A program causing page faults every few instructions is said to be thrashing.
Pre-paging
 Many paging systems try to keep track of each process‘working set and make sure
that it is in memory before letting the process run.
 Loading pages before allowing processes to run is called pre-paging.

(8) Explain the various page replacement strategies.


Various page replacement strategies are explained below.
Optimal Page Replacement Algorithm
 The moment a page fault occurs, some set of pages will be in the memory.
 One of these pages will be referenced on the very next instruction.
 Other pages may not be referenced until 10, 100, or perhaps 1000 instructions later.
 Each page can be labeled with the number of instructions that will be executed
before that page is first referenced.
 The optimal page algorithm simply says that the page with the highest label should
be removed.
 The only problem with this algorithm is that it is unrealizable.
 At the time of the page fault, the operating system has no way of knowing when
each of the pages will be referenced next.
FIFO Page replacement Algorithm
 The first in first out page replacement algorithm is the simplest page replacement
algorithm.
 The operating system maintains a list of all pages currently in memory, with the
most recently arrived page at the tail and least recent at the head.
 On a page fault, the page at head is removed and the new page is added to the tail.
 When a page replacement is required the oldest page in memory needs to be
replaced.
 The performance of the FIFO algorithm is not always good because it may happen

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

that the page which is the oldest is frequently referred by OS.


 Hence removing the oldest page may create page fault again. 
The Second Chance Page Replacement Algorithm
 A simple modification to FIFO that avoids the problem of throwing out a heavily
used page is to inspect the R bit of the oldest page.
 If it is 0, the page is both old and unused, so it is replaced immediately. If the R bit is
1, the bit is cleared, the page is put onto the end of the list of pages, and its load
time is updated as though it had just arrived in memory. Then the search continues.
 The operation of this algorithm is called second chance.
 What second chance is doing is looking for an old page that has not been referenced
in the previous clock interval. If all the pages have been referenced, second chance
degenerates into pure FIFO.

Figure 5-8. Operation of second chance. (a) Pages sorted in FIFO order. (b) Page list if a
page fault occurs at time 20 and A has its R bit set. The numbers above the pages are
their loading times.

The Clock Page Replacement Algorithm


 Although second chance is a reasonable algorithm, it is unnecessarily inefficient
because it is constantly moving pages around on its list.
 A better approach is to keep all the page frames on a circular list in the form of a
clock, as shown in Fig. 5-9.
 A hand points to the oldest page.
 When a page fault occurs, the page being pointed to by the hand is inspected.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

Figure 5-9. The clock page replacement algorithm.


 If its R bit is 0, the page is evicted, the new page is inserted into the clock in its
place, and the hand is advanced one position. If R is 1, it is cleared and the hand is
advanced to the next page.
 This process is repeated until a page is found with R = 0. Not surprisingly, this
algorithm is called clock.
 It differs from second chance only in the implementation.

LRU (Least Recently Used) Page Replacement Algorithm


 A good approximation to the optimal algorithm is based on the observation that
pages that have been heavily used in last few instructions will probably be heavily
used again in next few instructions.
 When page fault occurs, throw out the page that has been used for the longest
time. This strategy is called LRU (Least Recently Used) paging.
 To fully implement LRU, it is necessary to maintain a linked list of all pages in
memory, with the most recently used page at the front and the least recently used
page at the rear.
 The list must be updated on every memory reference.
 Finding a page in the list, deleting it, and then moving it to the front is a very time
consuming operations.
 There are other ways to implement LRU with special hardware.
 For a machine with n page frames, the LRU hardware can maintain a matrix of n × n
bits, initially all zero.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 Whenever page frame k is referenced, the hardware first sets all the bits of row k to
1, and then sets all the bits of column k to 0.
 At any instant, the row whose binary value is lowest is the least recently used; the
row whose value is next lowest is next least recently used, and so forth.
 The workings of this algorithm are given in Fig. 5-11 for four page frames and page
references in the order 0 1 2 3 2 1 0 3 2 3.
 After page 0 is referenced, we have the situation of Fig. 5-11(a).
 After page 1 is reference, we have the situation of Fig. 5-11(b), and so forth.
 As shown in Fig. 5-11(j), if page fault occurs at that moment, the page from the page
frame 1 with lowest binary value will be replaced.

Figure 5-11. LRU using a matrix when pages are referenced in the order 0, 1, 2, 3, 2, 1,
0, 3, 2, 3.

NRU (Not Recently Used)


 NRU makes approximation to replace the page based on R and M bits.
 When a process is started up, both page bits for all pages are set to 0 by operating
system.
 Periodically, the R bit is cleared, to distinguish pages that have not been referenced
recently from those that have been.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 When page fault occurs, the operating system inspects all the pages and divide
them into 4 categories based on current values of their R and M bits
 Case 0 : not referenced, not modified
 Case 1 : not referenced, modified
 Case 2 : referenced, not modified
 Case 3 : referenced, modified
 The NRU (Not Recently Used) algorithm removes a page at random from the lowest
numbered nonempty class.
 In given example,
 Page-0 is of class-2 (referenced, not modified)
 Page-1 is of class-1 (not referenced, modified)
 Page-2 is of class-0 ( not referenced, not modified)
 Page-3 is of class-3 (referenced, modified)
So lowest class page-2 needs to be replaced by NRU.

(9) Compare optimal, LRU and FIFO page replacement algorithms with illustration.
OR
For the Page Reference String: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1
Calculate the Page Faults applying (i) Optimal (ii) LRU and (iii) FIFO, Page
Replacement Algorithms for a Memory with three frames.
Optimal Page Replacement Algorithm
 The moment a page fault occurs, some set of pages will be in the memory.
 One of these pages will be referenced on the very next instruction (the page
containing that instruction).
 Other pages may not be referenced until 10, 100, or perhaps 1000 instructions later.
Each page can be labeled with the number of instructions that will be executed
before that page is first referenced.
 The optimal page algorithm simply says that the page with the highest label should
be removed.
 If one page will not be used for 8 million instructions and another page will not be
used for 6 million instructions, removing the former pushes the page fault that will
fetch it back as far into the future as possible.
 The only problem with this algorithm is that it is unrealizable.
 At the time of the page fault, the operating system has no way of knowing when
each of the pages will be referenced next.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

FIFO Page replacement Algorithm


 The first in first out page replacement algorithm is the simplest page replacement
algorithm.
 The operating system maintains a list of all pages currently in memory, with the
most recent arrived page at the tail and least recent at the head.
 On a page fault, the page at head is removed and the new page is added to the tail.
 When a page replacement is required the oldest page in memory needs to be
replaced.
 The performance of the FIFO algorithm is not always good because it may happen
that the page which is the oldest is frequently referred by OS.
 Hence removing the oldest page may create page fault again.

Page 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Requests
Frame 1 7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7
Frame 2 0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0
Frame 3 1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1
Page Faults F F F F F F F F F F F F F F F
(15)

LRU (Least Recently Used) Page Replacement Algorithm


 A good approximation to the optimal algorithm is based on the observation that
pages that have been heavily used in last few instructions will probably be heavily
used again in next few instructions.
 When page fault occurs, throw out the page that has been used for the longest
time. This strategy is called LRU (Least Recently Used) paging.
Page 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Requests
Frame 1 7 7 7 2 2 2 2 4 4 4 0 0 0 1 1 1 1 1 1 1
Frame 2 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0
Frame 3 1 1 1 3 3 3 2 2 2 2 2 2 2 2 2 7 7 7
Page Faults F F F F F F F F F F F F
(12)

(10) A computer has four page frames. The time of loading, time of last access and the

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

R and M bit for each page given below. Which page NRU, FIFO, LRU will replace.
Page Loaded Last Ref. R M
0 126 280 1 0
1 230 265 0 1
2 140 270 0 0
3 110 285 1 1
FIFO
 Page which is arrived first needs to be removed first, so here Page – 3 having
minimum loading time so as per FIFO page-3 needs to replace.
LRU (Least Recently Used)
 When page fault occurs, throw out the page that has been used for the longest
time.
 Page page-1 is not used for the long time from all four, so LRU suggest replacing
page-1.
NRU (Not Recently Used)
 NRU make approximation to replace based on R and M bits.
 When a process is started up, both page bits for all pages are set to 0 by operating
system.
 Periodically, the R bit is cleared, to distinguish pages that have not been referenced
recently from those that have been
 When page fault occurs, the operating system inspects all the pages and divide
them into 4 categories based on current values of their R and M bits
 Case 0 : not referenced, not modified
 Case 1 : not referenced, modified
 Case 2 : referenced, not modified
 Case 3 : referenced, modified
 The NRU (Not Recently Used) algorithm removed a page at random from the lowest
nonempty class.
 In given example
 Page-0 is of class-2 (referenced, not modified)
 Page-1 is of class-1 (not referenced, modified)
 Page-2 is of class-0 ( not referenced, not modified)
 Page-3 is of class-3 (referenced, modified)
 So lowest class page-2 needs to be replaced by NRU

(11) What is page fault handling? How OS handles page fault handling?

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

The sequence of events is as follows:


1. The hardware traps to the kernel, saving the program counter on the stack.

2. An assembly code routine is started to save the general registers and other volatile
information, to keep the operating system from destroying it.

3. The operating system discovers that a page fault has occurred, and tries to discover
which virtual page is needed. Often one of the hardware registers contains this
information. If not, the operating system must retrieve the program counter, fetch
the instruction, and parse it in software to figure out what it was doing when the
fault hit.

4. Once the virtual address that caused the fault is known, the system checks to see if
this address is valid and the protection consistent with the access. If not, the
process is sent a signal or killed. If the address is valid and no protection fault has
occurred, the system checks to see if a page frame is free. It no frames are free, the
page replacement algorithm is run to select a victim.

5. If the page frame selected is dirty, the page is scheduled for transfer to the disk,
and a context switch takes place, suspending the faulting process and letting
another one run until the disk transfer has completed. In any event, the frame is
marked as busy to prevent it from being used for another purpose.

6. As soon as the page frame is clean (either immediately or after it is written to disk),
the operating system looks up the disk address where the needed page is, and
schedules a disk operation to bring it in. While the page is being loaded, the
faulting process is still suspended and another user process is run, if one is
available.

7. When the disk interrupt indicates that the page has arrived, the page tables are
updated to reflect its position, and the frame is marked as being in normal state.

8. The faulting instruction is backed up to the state it had when it began and the
program counter is reset to point to that instruction.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

9. The faulting process is scheduled, and the operating system returns to the
assembly language routine that called it.

10. This routine reloads the registers and other state information and returns to user
space to continue execution, as if no fault had occurred.

(12) What is Segmentation? Explain.


 Virtual memory is one-dimensional in nature because the virtual address space go
from 0 to some maximum address, one address after another.
 There are many problems where separate virtual address space for different
entities of process is much better.
Segment
 A general solution is to provide the machine with many independent address
spaces called segments.
 Each segment consists of a linear sequence of addresses, from 0 to the maximum
allowed.
 Different Segments may have different lengths.
 Segment lengths may change during execution.
 Different Segments can grow or shrink independently without affecting each other.
 To specify address in these segments or two dimensional memories, the program
must supply a two part address, a segment number and address within the
segment.
Advantages of Segmentation
 Segmentation provides simplified data structure to handle growing and shrinking of
data.
 If each procedure occupies a separate segment, with address 0 as its starting
address, the linking of procedures compiled separately is simplified.
 If the procedure in segment n is modified and recompiled, no other procedures
need to be changed.
 Segmentation also facilitates sharing procedures or data between several
processes. A common example is shared library.
 Each segment forms a logical entity of which the programmer is aware, such as
procedure, or an array, or a stack, different segments can have different kind of
protection.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 In paging system programmer is unaware of the content of pages, but in


segmentation user knows in advance the content of the segments.
Paged Segmentation
 Generally in segmented memory swapping done entirely in segment wise. Entire
segment get swapped-out or swapped-in.
 If segments are large, it may be inconvenient or even impossible to keep them in
main memory in their entirely.
 Idea of paging the segments is practical one, so only those pages from segments
that are actually needed have to be around, these concept dividing segments into
pages is called paged segmentation.

Symbol Parse
Table Tree Call
Source Stack
Text

Constants
Segment Segment Segment Segment Segment
0 1 2 3 4

Different Logical Segments of Compiler having five tables


Figure 5-12. A segmented memory allows each table to grow or shrink independently

 Here, an example of MULTICS is considered to understand segmentation with


paging.
 Segmented memory Virtual Address consists of two parts: the segment number and
address within segment, the address within segment is further divided into a page
number and a word within a page.
 Program has a segment table, with one entry per segment, its entry contains pointer
to its page table.
 When memory reference occurs, the following steps occur…
o The segment number used to find segment descriptor.
o Check is made to see if the segment’s page table is in memory.
 If not, segment fault occurs.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 If there is a protection violation, a fault (trap) occurs.


o Page table entry for the requested virtual page examined.
 If the page itself is not in memory, a page fault is triggered.
 If it is in memory, the main memory address of the start of the page
is extracted from the page table entry
o The offset is added to the page origin to give the main memory address
where the word is located.
o The read or store finally takes place.

Figure 5-13. A 34-bit MULTICS virtual address.

Figure 5-14 (a). The MULTICS virtual memory. The descriptor segment points to the
Page tables.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

Figure 5-14. The MULTICS virtual memory. (b) A segment descriptor. The numbers are
the field lengths.

(13) Discuss the issues associated with paging and solution of it.
 In any paging system, two major issues must be faced:
1. The mapping from virtual address to physical address must be fast.
2. If the virtual address space is large, the page table will be large.
The mapping from virtual address to physical address must be fast.
 In the absence of paging, to fetch an instruction requires only one memory
reference.
 With paging, one more memory reference is required to access the page table.
 Since execution speed is generally limited by the rate at which the CPU can get
instructions and data out of the memory, having to make two memory references
per instruction reduce performance by half.
 Most programs access a small number of pages frequently.
 The solution that has been devised is to equip computers with a small hardware
device for mapping virtual addresses to physical addresses without going through
the page table.
 The device, called a TLB (Translation Lookaside Buffer) or sometimes an associative
memory, is illustrated in Fig. 5-15.
 It is usually inside the MMU and consists of a small number of entries, eight in this
example, but rarely more than 256.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

Figure 5-15. A TLB to speed up paging.

 Each entry contains information about one page, including the virtual page
number, a bit that is set when the page is modified, the protection code
(read/write/execute permissions), and the physical page frame in which the page is
located.
 These fields have a one-to-one correspondence with the fields in the page table,
except for the virtual page number, which is not needed in the page table. Another
bit indicates whether the entry is valid (i.e., in use) or not.
 Let us now see how the TLB functions.
 When a virtual address is presented to the MMU for translation, the hardware first
checks to see if its virtual page number is present in the TLB by comparing it to all
the entries simultaneously (i.e., in parallel).
 Doing so requires special hardware, which all MMUs with TLBs have.
 If a valid match is found and the access does not violate the protection bits, the
page frame is taken directly from the TLB, without going to the page table.
 If the virtual page number is present in the TLB but the instruction is trying to write
on a read-only page, a protection fault is generated.
 When the virtual page number is not in the TLB, the MMU detects the miss and
does an ordinary page table lookup.
 It then evicts one of the entries from the TLB and replaces it with the page table
entry just looked up.
 Thus if that page is used again soon, the second time it will result in a TLB hit rather
than a miss.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 When an entry is purged from the TLB, the modified bit is copied back into the
page table entry in memory.
 The other values are already there, except the reference bit. When the TLB is
loaded from the page table, all the fields are taken from memory.

Figure 5-16. Translation Lookaside buffers Example

If the virtual address space is large, the page table will be large.
There are two ways of dealing with very large virtual address spaces.
1. Multilevel Page Tables
 The secret to the multilevel page table method is to avoid keeping all the page
tables in memory all the time.
 In particular, those that are not needed should not be kept around.
 In Fig. 5-17(b) we see how the two-level page table works.
 On the left we see the top-level page table, with 1024 entries, corresponding to the
10-bit PT1 field.
 When a virtual address is presented to the MMU, it first extracts the PT1 field and
uses this value as an index into the top-level page table.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

 Each of these 1024 entries in the top-level page table represents 4M because the
entire 4-gigabyte (i.e., 32-bit) virtual address space has been chopped into chunks
of 4096 bytes.
 The entry located by indexing into the top-level page table yields the address or the
page frame number of a second-level page table.
 Entry 0 of the top-level page table points to the page table for the program text,
entry 1 points to the page table for the data, and entry 1023 points to the page
table for the stack.
 The other (shaded) entries are not used. The PT2 field is now used as an index into
the selected second-level page table to find the page frame number for the page
itself.

Figure 5-17. (a) A 32-bit address with two page table fields. (b) Two-level
page tables.

2. Inverted Page Tables


 An alternative to ever-increasing levels in a paging hierarchy is known as inverted
page tables.
 In this design, there is one entry per page frame in real memory, rather than one

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

entry per page of virtual address space.


 For example, with 64-bit virtual addresses, a 4-KB page size, and 4 GB of RAM, an
inverted page table requires only 1,048,576 entries.
 The entry keeps track of which (process, virtual page) is located in the page frame.
 Although inverted page tables save lots of space, at least when the virtual address
space is much larger than the physical memory, they have a serious down-side:
virtual-to-physical translation becomes much harder.
 The solution is to make use of the TLB.
 If the TLB can hold all of the heavily used pages, translation can happen just as fast
as with regular page tables.
 On a TLB miss, however, the inverted page table has to be searched in software.
 One feasible way to accomplish this search is to have a hash table hashed on the
virtual address.

Figure 5-18. Comparison of a traditional page table with an inverted page table.

 All the virtual pages currently in memory that have the same hash value are
chained together, as shown in Fig. 5-18.
 If the hash table has as many slots as the machine has physical pages, the average
chain will be only one entry long, greatly speeding up the mapping.
 Once the page frame number has been found, the new (virtual, physical) pair is
entered into the TLB. 

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


Memory management

(14) Compare paging and segmentation.

Paging Segmentation
Paging was invented to get large address Segmentation was invented to allow programs
apace without having to buy more physical and data to be broken up into logically
memory. independent address space and to add sharing
and protection.
The programmer does not aware that paging The programmer is aware that segmentation is
is used. used.
Address space is one dimensional. Many independent address spaces are there.
Procedure and data cannot be distinguished Procedure and data be distinguished and
and protected separately. protected separately.
Change in data or procedure requires Change in data or procedure requires compiling
compiling entire program. only affected segment not entire program.
Sharing of different procedures not available. Sharing of different procedures available.

Haresh Khachariya Dept: CS&IT | – Operating System (2020-21)


2 – Introduction to UNIX

(1) What is Unix? What is Linux?


 UNIX is a powerful operating system originally developed at AT&T Bell Labs.
 It is very popular among the scientific, engineering, and academic communities due to
its multi-user and multi-tasking environment, flexibility and portability, electronic mail
and networking capabilities, and the numerous programming, text processing and
scientific utilities available.
 The UNIX system is mainly composed of three different parts: the kernel, the file
system, and the shell.
 The kernel is that part of the system which manages the resources of whatever
computer system it lives on, to keep track of the disks, tapes, printers, terminals,
communication lines and any other devices.
 The file system is the organizing structure for data. The file system is perhaps the most
important part of the Linux operating system. The file system goes beyond being a
simple repository for data, and provides the means of organizing the layout of the data
storage in complex ways.
 The shell is the command interpreter. Although the shell is just a utility program, and is
not properly a part of the system, it is the part that the user sees. The shell listens to
your terminal and translates your requests into actions on the part of the kernel and
the many utility programs
 Linux is a freely available, open source, Unix-like operating System. Written originally
for the PC by Linus Torvalds (A young student in the University of Helsinki), with the
help of many other developers across the internet.
 Linux now runs on multiple hardware platforms, from the smallest to the largest, and
serves a wide variety of needs from servers to movie-making to running businesses to
user desktops.

(2) Explain the Features of the Unix in detail.


 The following features are provided by the UNIX operating System.
 Open Source
 Linux source code is freely available and it is community based development
project.
 Multiple teams are working in collaboration to enhance the capability of Linux
operating system and it is continuously evolving.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX

 Multiuser capability
 In a multi user system the same computer resources hard disk, memory etc are
accessible to the many users.
 Users are given the different terminal to operate, a terminal in turn, is a keyboard
and a monitor. All the terminals are connected to the main computer whose
resources are available by all users.
 So the user at any of the terminals cannot use only the computer but also any
devices that may be attached like a printer.

 Multitasking capability
 It means that it is capable of carrying out more than one job at the same time it
allow you to type in a program in its editor while simultaneously executes some
other command you might have given earlier.
 Say for example you might have given earlier sort and copy a huge file this job will
perform in the background while in foreground you use editor.
 This is managed by dividing the CPU time between all processes being carrying out.

 Communication
 UNIX has the excellent communication with the users. The communication may be
within the network of a single main computer or between two or more such
computer network.
 The users can easily exchange mail, data, and programs through such networks.

 Security
 Unix Has the three provisions for protecting the data. The first is provided by
assigning the passwords and login names to the individual users and ensuring that
nobody has excess to your work.
 All the five have the read write and execute permissions to each file which decide
who can excess a particular file, which can modify and execute it.
 Lastly there is a file encryption utility which encodes your file into an unreadable
format so even if someone succeeds in opening it your secrets are safe.

 Portability
 Portability means software can works on different types of hardware in same way.
 It is one of the main reasons for the popularity of the Unix. It can be ported to
almost any computer system with only the minimum adoptions.
Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)
2 – Introduction to UNIX
 A portability credit of the UNIX is because of the C language, it written in C
language and C language is portable.

(3) Explain Linux Architecture.

User

Utility Program

Standard library

UNIX operating system (Kernel)

Hardware

 Hardware
 The bottom layer is hardware.
 It contains physical devices of computer like CPU, Memory, Disk, printer etc.
 UNIX kernel will interface with this hardware.

 UNIX Kernel
 Kernel is program which provides services of OS like memory management, file
management and process management.
 Kernel will provide interface with hardware and user programs.

 Standard library
 It contains set of procedures.
 This is collection of system level files.

 Utility program:
 Utility programs are used to make user programs and make work easier.
 Utility programs like compilers, assemblers, editors etc.

 User
 User programs are comes for processing and interact with system.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX

(4) Explain the Linux Kernel Structure.


 The following Figure shows the overall structure of the Linux. The kernel sits directly on
the hardware and enables the interactions with I/O devices and memory management.

Structure of the Linux kernel

 At the lowest level it contains interrupt handlers which are the primary way for
interacting with the device, and low level dispatching mechanism.
 The dispatching occurs when an interrupt happens and also when the kernel completes
some operations and it is time to start up a user process again.
 Now we divide the various kernel subsystems into the three main components. The I/o
component contains the kernel pieces and responsible for interacting with the devices
and performing the network and storage I/O operations.
 At the highest level the I/O operations are all integrated under a virtual file system and
at lowest level, all I/O operations pass through some device driver.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX

 All Linux drivers are classified as either a character device driver or block device drivers,
with the main difference that random accesses are allowed on the block devices and
not on the character devices.
 Technically network devices are really character devices, but they are handled
somewhat differently, so It is preferable to separate them.
 The layer above the network drivers handle a kind of the routing function and making
sure that the right packet goes to the right devices.
 Sockets interface which allows the program to create sockets for the particular
network.
 On the top of the disk drivers is the I/O scheduler who is responsible for ordering and
issuing disk operation request in a way that tries to converse waste full disk head
movement.
 At the very top of the block device column are the file systems Linux may have the
multiple file system excising concurrently. In order to hide the architectural differences
of the various hardware devices from the file system implementation, a generic block
device layer provides an abstraction layer used by all file system.
 At the right side of the fig there are two key components of the Linux kernel these are
responsible for the memory and process management tasks.
 Memory management tasks include maintaining the virtual to physical memory
mappings, maintaining a cache of the recently accessed pages and implementing a good
page replacement policy.
 The key responsibility of the process management component is the creation and
termination of the process. It also includes the process scheduler and code for the
signal handling.
 Finally at the very top is the system call interface in to the kernel. All system calls come
here, causing a trap which switches the execution from the user mode in to the kernel.
Mode.

(5) Explain the directory Structure or file system structure of the Unix/linux.
 The initial Linux file system was the MINIX 1 file system. However, infect it limited file
names to 14 characters and its maximum file size was 64 MB.
 The first improvement was the ext files system which allow file names of 255 characters
and file size of 2 GB, but it was slower than MINIX 1 file system so the ext 2 file system
was invented, with long file name, long file, and better performance and it has became

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
the main file system.
 A Linux file is sequence of 0 or more bytes containing arbitrary information. No
distinction is made between ASCII file, binary file or any other kinds of the file.
 File names consists of a based name and an extension, separated by a dot. For example
prog.c is c program anprog.o is an object file. Extension may be of any length and file
may have multiple extensions, for example prog.java.gz is a compressed java program.
 File can be grouped together in directories. Directories are stored as a files and it can be
treated like files.
 The / characters is known as the root directory and also use to separate directory
names.
x Contents
bin Binary (executable) programs
dev Specials files for I/O devices
etc Miscellaneous system files
lib Libraries
usr User directories
Some important directory found in most Linux systems

 /:
 This is the root directory which should contain only the directories needed at the top level of the
file structure.
 /bin:
 This is where the executable files are located. They are available to all user.
 /dev:
Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)
2 – Introduction to UNIX
 It includes files for devices, holds the software necessary to update peripherals such as printers
and terminal.
 /etc:
 It contains various administrative files such as lists of user name and passwords, configuration
files, disk configuration files.
 /mnt
 Used to mount other temporary file systems, such as cdrom and floppy for the CD-ROM drive and
floppy diskette drive, respectively
 /home
 Contains the home directory for users and other accounts.
/tmp
 Holds temporary files used between system boots
/usr
 Used for miscellaneous purposes, or can be used by many users. Includes administrative
commands, shared files, library files, and others
/var
 Typically contains variable-length files such as log and print files and any other type of file that
may contain a variable amount of data

 There are 2 ways to specify file names in Linux.


1) Absolute path :-
 It tells us how to get the file starting at the root directory. For example / usr/ ast/
books/ mos3/ chap-10. This tells system to look in the root directory for an usr
directory. Then looks for the directory ast. The ast directory contains book
directory which contains the mos3 directory which contains the file chap-10.
2) Relative path :-
 Absolute path name are often long and inconvenient for this reason Linux allows
the users to designate the directory in which they are currently working as the
working directory. A path name specified relative to the working directory is a
relative path. For example if / usr/ ast /books/mos3 is the working directory

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
(6) Explain the role or function of the kernel.
 Each process asks for the system resources like computing power, memory network
connectivity etc. The kernel is the bulk of the executable code in charge of handling
such request.
 The kernel is the main component of most computer operating systems. It is a bridge
between applications and the actual data processing done at the hardware level.
The following are the major role of the kernel :
 Resource allocation :-
 The kernel's primary function is to manage the computer's resources and allow

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
other programs to run and use these resources. These resources are- CPU, Memory and I/O devices.
 Process Management :-
 The kernel is in charge of creating, destroying and handling the input output of the
process.
 Communications amongst the different processes is the responsibility of the kernel.
 Memory Management :-
 The memory is the major resource of the computer and the policy used to deal
with it is a critical.
 The kernel builds a virtual address space for all the process on the top of the
resource. The different parts of the kernel interact with the memory management
subsystem by using the function calls.
 File System :-
 The kernel builds the structured file system on the top of the unstructured
hardware.
 Kernel also supports the multiple file system types that is different way of
managing the data.
 Device Control :-
 Every system maps into the physical device.
 All the device control operations are performed by the code that is specific to the
device being addressed. This code is called device driver.
 Networking :-
 It will be managed by the operating system and also control the program execution
according to the network activity.
 Routing and address resolution issues are also handled by the kernel.
 Inter - Process Communication
 Kernel provides methods for Synchronization and Communication between
processes called Inter- Process Communication (IPC).
 There are various approaches of IPC say, semaphore, shared memory, message
queue, pipe (or named fifo), etc.
 Security or Protection Management
 Kernel also provides protection from faults (error control) and from malicious
behaviors (Security).
 One approach toward this can be Language based protection system, in which the
kernel will only allow code to execute which has been produced by a trusted
Language compile

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX

(7) Explain in brief roles/ functions of shell.


 UNIX shell act as a command interpreter.
 It gathers input from user and executes programs based on that input, when a
program finishes executing; it displays that program's output.
 It is primary interface between a user sitting at his terminal and operating system,
unless the user is not using a graphical interface.
 A shell is an environment in which user can run our commands, programs, and shell
scripts.
 There can various kinds of shells such as sh (bourne shell), csh (C shell), ksh (korn
shell) and bash.
 When any user logs in, a shell is started.
 The shell has the terminal as standard input and standard output.
 It starts out by typing the prompt, a character such as $, which tells user that shell is
waiting to accept command at user level if you are root then sign is #.
 For example if user types date command,
$ date
sat Mar 12 08:30:19 IST 2016
 The shell creates a child process and runs date program as child.
 While the child process is running, the shell waits for it to terminate.
 When child finishes, the shell types the prompt again and tries to read the next input
line.
 Shell is work as interface, command interpreter and programming language.

 Shell - As interface
 Shell is interface between user and computer.
 User can directly interact with shell.
 Shell provide command prompt to user to execute commands.
 Shell - As command interpreter
 It read command enter by user on prompt.
 It Interpret the command, so kernel can understand it easily.
 Shell - As programming language
 Shell is also work as programming language.
 It provides all features of programming language like variables, control structures
and loop structures.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
 Cshell : -
 The C shell was written by Bill Joy at the University of California at Berkeley. His main intent for
writing the C shell was to create a shell with C language-like syntax.
• Customizable environment. The C shell has three separate files which are used for customizing its
environment. These three files are .cshrc, .login, and .logout.

 Abbreviate commands. (Aliases.)


 History. (Remembers commands typed before.)
 Job control. (Run programs in the background or foreground.)
 Shell scripting. (One can write programs using the shell.)
 Keyboard shortcuts.
 Default prompt is % denoted as csh %.

 Korn shell : -
 The Korn shell uses two startup files, the .profile and the .kshrc. The .profile is read once, by your
login ksh, while the .kshrc is read by each new ksh.
 The Korn shell was developed in the early 1980s by David Korn of AT&T labs, and contains many
similar features to the sh and csh shells.
 The Korn shell has an advantage over the traditional Unix shell in that it contains the
functionality of many scripting and programming languages, such as perl and awk, meaning that
programs can be run quickly and efficiently within the Korn shell.
 Default prompt is $ denoted as ksh.
 Bourne shell : -
 It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It is faster and
more preferred. It lacks features for interactive use like the ability to recall previous commands.
It also lacks built-in arithmetic and logical expression handling. It is default shell for Solaris OS.
 Default prompt is $ for user denoted as sh.
 Bourne-again shell : -
 The Bourne-Again Shell (bash) is a clone of the Bourne shell, written and licensed under the GNU
General Public License, meaning the code for the shell, as well as the shell itself, is freely
available.
 The bash shell runs using very similar syntax to the sh, ksh and csh shells. However, there are
some small changes with the bash shell. For example, the bash shell runs under all GNU/Linux
variant operating systems, such as Ubuntu and Debian.
 The bash shell also supports many interactive features, such as a command history that can be
accessed with a few keystrokes.
 It is the default shell on Linux operating system.
 Default prompt is $ for user denoted as bash.

Note * Root user default prompt is hostname #.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
(8) Files and Directory permission:
Permission level:
UGOA:
user –
The user permissions apply only the owner of the file or directory, they will not impact the actions of
other users.
group –
The group permissions apply only to the group that has been assigned to the file or directory, they will
not effect the actions of other users.
others –
The others permissions apply to all other users on the system, this is the permission group that you
want to watch the most.
all users –
The All Users permissions apply to all other users on the system, this is the permission group that you
want to watch the most.
Permission Types:
RWX-:
 read – The Read permission refers to a user’s capability to read the contents of the file.
 write – The Write permissions refer to a user’s capability to write or modify a file or directory.
 execute – The Execute permission affects a user’s capability to execute a file or view the contents of a
directory.
 - no permission.
How to assign permission:

Symbolic Mode
In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify
permissions of a specific owner. It makes use of mathematical symbols to modify the file permissions.
Operator Description

+ Adds a permission to a file or directory

- Removes the permission

= Sets the permission and overrides the


permissions set earlier.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
The octal notations
You can also use octal notations like this.

Absolute(Numeric) Mode
In this mode, file permissions are not represented as characters but a three-digit octal number.
The table below gives numbers for all for permissions types.

Number Permission Type Symbol

0 No Permission ---

1 Execute --x

2 Write -w-

3 Execute + Write -wx

4 Read r--

5 Read + Execute r-x

6 Read +Write rw-

7 Read + Write +Execute rwx

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
Let's see the chmod command in action.

In the above-given terminal window, we have changed the permissions of the file 'sample to '764'.

'764' absolute code says the following:


 Owner can read, write and execute
 Usergroup can read and write
 World can only read
This is shown as '-rwxrw-r-
This is how you can change the permissions on file by assigning an absolute number.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


2 – Introduction to UNIX
(9) Give comparison of UNIX and Windows Operating System.
 UNIX is a open source operating system (we can modify the code), easily available free
of cost. Windows requires licensing and is a paid operating system.
 UNIX is a command based operating system while windows is menu based.
 In UNIX I/O components are stored as file while windows does not support this
functionality.
 Windows must boot from a primary partition. UNIX can boot from either a primary
partition or a logical partition inside an extended partition.
 Windows allows programs to store user information (files and settings) anywhere. This
makes it impossibly hard to backup user data files and settings and to switch to a new
computer.
 UNIX is CLUI (Command Line User Interface) operating system while a window is GUI
(Graphical User Interface) Operating System.
 Windows program are event driven i.e. main program waits for some events to happen
and calls a procedure to handle it. In contrast unix program consist of code that does
something or makes system calls to get some services done.
 In UNIX there is one to one relation between system calls and library procedures, while
in windows library calls and system calls are decoupled. Win 32 API(Application
Program Interface) are used to get operating system services.
 UNIX supports various functionality as linking files, mounting and unmounting of files,
file permissions using chmod command, which are not present in windows.
 UNIX is less affected by viruses and malwares and hence more secure compared to
windows.
 Examples of UNIX operating system are Ubuntu, Fedora, Red Hat, Debian, Archlinux,
Androidetc while examples of windows operating system are Windows 8, 8.1, 7, Vista,
XP.

Haresh Khachariya Dept:CS&IT| – Operating System (2020-21)


Unix Commands

1) cal:- Displays a calendar


Syntax:- cal [options] [ month ] [year]
Description :-
 cal displays a simple calendar. If arguments are not specified, the current month is
displayed. The switching options are as follows:
-1 Display single (current) month output. (This is the default.)
-3 Display prev/current/next month output
-s Display Sunday as the first day of the week (This is the default.)
-m Display Monday as the first day of the week
-j Display Julian dates (days one-based, numbered from January 1)
-y Display a calendar for the current year
Example:-
$cal
or
$cal 02 2016
Feb 2016

Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29

2) clear :- It clears the terminal screen.


Syntax :- clear
Description :-
 Clear clears your screen if this is possible, including its scroll back buffer.
 Clear ignores any command-line parameters that may be present.

3) pwd :- Displays path from root to current directory


Syntax :- pwd [options]
Example:
$ pwd
/home/kumar/progs

4) cd:- It is used to change the directory.


Syntax :- cd [directory]
Description:-

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

 Used to go back one directory on the majority of all UNIX shells. It is important
that the space be between the cd and directory name or ..
Example:-
$ pwd
/home/kumar
$ cd progs
$ pwd
/home/kumar/progs
$ cd ..
/home/kumar

5) ls:- Lists the contents of a directory


Syntax :- ls [options]
Description :-
-a Shows you all files, even files that are hidden (these files begin with a dot.)
-A List all files including the hidden files. However, does not display the working
directory (.) or the parent directory (..).
-d If an argument is a directory it only lists its name not its contents
-l Shows you huge amounts of information (permissions, owners, size, and when last
modified.)
-p Displays a slash ( / ) in front of all directories
-r Reverses the order of how the files are displayed
-R Includes the contents of subdirectories
Example:-
$ ls – l
-rw-r----- 1 student student 23 Jan 16 15:27 file1.txt
Field Explanation:
 If first character is – then it is normal file
 If it is d then it is directory
 Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3
characters refers to the read, write, execute permissions for user, group and world
In this example, -rw-r—– indicates read-write permission for user, read permission
for group, and no permission for others.
 Field 2 – Number of links: Second field specifies the number of links for that file. In
this example, 1 indicates only one link to this file.
 Field 3 – Owner: Third field specifies owner of the file. In this example, this file is
owned by username ‘student’.
 Field 4 – Group: Fourth field specifies the group of the file. In this example, this file
belongs to ”student’ group.
 Field 5 – Size: Fifth field specifies the size of file. In this example, ’13′ indicates the

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

file size.
 Field 6 – Last modified date & time: Sixth field specifies the date and time of the
last modification of the file. In this example, ‘Jan 16 15:27′ specifies the last
modification time of the file.
 Field 7 – File or directory name: The last field is the name of the file or directory.
In this example, the file name is file1.txt

6) exit :- It is used to terminate a program, shell or log you out of a network normally.
Syntax :- exit

7) echo :- It prints the given input string to standard output.


Syntax :- echo string
Example:-
$ echo “hi.. hello unix”
hi.. hello unix

8) who :- who command can list the names of users currently logged in, their terminal, the
time they have been logged in, and the name of the host from which they have logged in.
Syntax :- who [options] [file]
Description:-
Print the username of the invoking user, The 'am' and 'i' must be space
am i
separated.
-b Prints time of last system boot.
-d print dead processes.
-H Print column headings above the output.
Include idle time as HOURS:MINUTES. An idle time of . indicates activity
-l
within the last minute.
-m Same as who am i.
-q Prints only the usernames and the user count/total no of users logged in.
Example :-
$ who
dietstaffpts/1 2016-02-20 22:42 (:0.0)
dietstaffpts/2 2016-02-20 09:30 (:0.0)
 Here first column shows user name, second shows name of the terminal the user
is working on. Third& fourth column shows date and time of logging, last column
shows machine name.

9) who am i:- Print effective userid


Syntax :- who am i

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

Description: - Print the user name associated with the current effective user id.
Example :-
$ who am i
dietstaffpts/3 2016-02-10 08:52 (:0.0)
 Here first column shows user name, second shows name of the terminal the user
is working on. Third & fourth column shows date and time of logging, last column
shows machine name.

10) mkdir:- This command is used to create a new directory


Syntax :- mkdir [options] directory
Description :-

-m Set permission mode (as in chmod)


-p No error if existing, make parent directories as
needed.
-v Print a message for each created directory
directory The name of the directory that you wish to
create
Example:-
$ mkdir aaa
 The above command will create directory named aaa under the current directory.
We can also create number of subdirectories with one mkdir command.

11) rmdir:- It is used to delete/remove a directory and its subdirectories.


Syntax :- rmdir [options..] Directory
Description :-
 It removes only empty directory.

-p Allow users to remove the directory and its parent directories which become
empty.

12) bc:- bc command is used for command line calculator. It is similar to basic calculator. By
using which we can do basic mathematical calculations.
Syntax :- bc [options]
Description :-
 bc is a language that supports arbitrary precision numbers with interactive
execution of statements.
 bc starts by processing code from all the files listed on the command line in the
order listed. After all files have been processed, bc reads from the standard input.
All code is executed as it is read.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-q To avoid bc welcome message


-l To include math library functionalities

Example:-
$ bc
bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This
is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 2*3
6
 The above command used is for mathematical calculations.
$ bc -l
bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This
is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'.11+2
13
 The above command displays the sum of '11+2'.
$ bc calc.txt
bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This
is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 13
 'calc.txt' file have the following code:11+2. Get the input from file and displays the
output.

13) uname:- It is used to print system information.


Syntax :- uname [options]
Description :-
 Print certain system information.
-s print the kernel name
-n print the network node hostname
-r print the kernel release
-v print the kernel version
-m print the machine hardware name
-o print the operating system
Example:-
$ uname
Linux

14) tty:- Print the file name of the terminal connected to standard input.
Syntax :- tty
Description :-
 tty writes the name of the terminal that is connected to standard input onto

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

standard output.
 Command is very simple and needs no arguments.
Example :-
$tty
/student/tty10

15) stty:- Change and print terminal line settings.


Syntax :- sty
Description :-
 stty sets certain terminal I/O modes for the device that is the current standard
input.
 Without arguments, it writes the settings of certain modes to standard output.

Example :-
$ sty
speed 19200 baud, 25 rows, 79 columns
kill = ^U

16) cat:- It is used to create, display and concatenate file contents.


Syntax : - cat [options] [FILE]...
Description :-
-A Show all.
-b Omits line numbers for blank space in the output.
-e A $ character will be printed at the end of each line prior to a new line.
-E Displays a $ (dollar sign) at the end of each line.
-n Line numbers for all the output lines.
-s If the output has multiple empty lines it replaces it with one empty line.
-T Displays the tab characters in the output.
Non-printing characters (with the exception of tabs, new-lines and form-feeds) are
-v
printed visibly.

 Two basically three uses of the cat command.


1) Create new files.
2) Display the contents of an existing file.
3) Concatenate the content of multiple files and display.
Example :-
$ cat file1.c
 Above syntax will display the content of file1.c
$ cat > file1.c
 Above syntax creates file1.c and allow us to insert content for this file.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

 After inserting content you can use ctrl+d to exit the file.
 If file with same name exist then it will overwrite that file.

$ cat file1.c
process management
memory management
file mgmt
$ cat file1.c >> file2.c
 It can concatenate the contents of two files. For this you have to use append
output redirection operator.
 The contents of file2.cwill be appended to file1.c.

17) cp:- cp command copy files from one location to another. If the destination is an existing
file, then the file is overwritten; if the destination is an existing directory, the file is copied
into the directory (the directory is not overwritten).
Syntax :- cp [options]... source destination
Description:-
 Here, after cp command contents of both source file and destination file files are
the same.
 It will copy the content of source file to destination file.
 If the destination file doesn’t exist, it will be created.
 If it exists then it will be overwritten without any warning.
 If there is only one file to be copied then destination can be the ordinary file or the
directory file.
-a archive files
-f force copy by removing the destination file if needed
-i interactive - ask before overwrite
-l link files instead of copy
-L follow symbolic links
-n no file overwrite
-u update - copy when source is newer than dest
Example:-
$ cp file1 file2
 The above cp command copies the content of file1.php to file2.php.
Copy folder and subfolders:
$ cp-R scripts scripts1
 The above cp command copy the folder and subfolders from scripts to scripts1

18) rm:- It is used to remove/delete the file from the directory.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

Syntax :- rm [options..] [file|directory]


Description :-
 Files can be deleted with rm. It can delete more than one file with a single
invocation. For deleting a single file we have to use rm command with filename to
be deleted.
 Deleted file can’t be recovered. rm can’t delete the directories. If we want to
remove all the files from the particular directory we can use the * symbol.

-f Ignore nonexistent files, and never prompt before removing.


-i Prompt before every removal.
Examlple :-
$ rm myfile.txt
 Remove the file myfile.txt. If the file is write-protected, you will be prompted to
confirm that you really want to delete it.
$ rm *
 Remove all files in the working directory. If it is write-protected, you will be
prompted before rm removes it.
$ rm -f myfile.txt
 Remove the file myfile.txt. You will not be prompted, even if the file is write-
protected; if rm can delete the file, it will.
$ rm -f *
 Remove all files in the working directory. rm will not prompt you for any reason
before deleting them.
$ rm -i *
 Attempt to remove every file in the working directory, but prompt before each file
to confirm.

19) mv:- It is used to move/rename file from one directory to another.


Syntax :- mv [options] oldname newname
Description :-
 mv command which is short for move.
 mv command is different from cp command as it completely removes the file from
the source and moves to the directory specified, where cp command just copies
the content from one file to another.
 mv has two functions: it renames a file and it moves a group of files to a different
directory. Mv doesn’t create a copy of the file , it merely renames it. No additional
space is consumed on disk during renaming. For example if we rename a file os to
os1 and then if we try to read file os we will get error message as it is renamed to
os1 there is no existence of file named os.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-f mv will move the file(s) without prompting even if it is writing over an


existing target. Note that this is the default if the standard input is not a
terminal
-i Prompts before overwriting another file
Example:-
$ cat file1
Memory
Process
Files
$ mv file1 file2
 rename file1 to file2
 If the destination file doesn’t exist it will be created. mv can also be used to
rename a directory. A group of files can also be moved to a directory. mv doesn’t
prompt for overwriting destination file if it exists.

20) nl :-
nl numbers the lines in a file.
Syntax: - nl [OPTION] [FILE]
Example :-
$cat list.txt
apples
oranges
potatoes
lemons
garlic
$nl list.txt
1 apples
2 oranges
3 potatoes
4 lemons
5 garlic
 In the above example, we use the cat command to display the contents of list.txt.
Then we use nl to number each line and display the result to standard output.
$nl list.txt > nlist.txt
$cat nlist.txt
1 apples
2 oranges
3 potatoes
4 lemons

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

5 garlic
 In the above example, we run the same nl command, but redirect the output to a
new file, nlist.txt. Then we use cat to display the results.

21) cut :- cut command is used to cut out selected fields of each line of a file. The cut
command uses delimiters to determine where to split fields.
Syntax :- cut [options] filename
Description :-
file A path name of an input file. If no file operands are specified, or if a file
operand is -, the standard input will be used
-c The list following -c specifies character positions
-d The character following -d is the field delimiter
-f select only these fields on each line
-b Select only the bytes from each line as specified in LIST
Example :-
 For example, let's say you have a file named data.txt which contains the following
text:
one two three four five
alpha beta gamma delta epsilon
 In this example, each of these words is separated by a tab character, not spaces.
The tab character is the default delimiter of cut, so it will by default consider a
field to be anything delimited by a tab.
 To "cut" only the third field of each line, use the command:
$ cut -d’ ‘ -f 3 data.txt
three
gamma
 let's say you want the third field and every field after it, omitting the first two
fields. In this case, you could use the command:
$ cut -d’ ‘ -f 3- data.txt
three four five
gamma delta epsilon
$ cut -c 3 file.txt
r
m
 For example, to output only the third-through-twelfth character of every line of
data.txt, use the command:
$ cut -c 3-12 data.txt
e two thre
pha beta g

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

22) paste:- paste command is used to paste the content from one file to another file. It is also
used to set column format for each line.
Syntax :- paste [option] file
Description :-
 Paste prints lines consisting of sequentially corresponding lines of each specified
file. In the output the original lines are separated by TABs. The output line is
terminated with a newline.

-d Specify of a list of delimiters.


-s Paste one file at a time instead of in parallel.
File A path name of an input file. If - is specified for one or more of the file s, the
standard input will be used.
Example:-
$ cat > a
Unix
Linux
Windows
$ cat > b
Dedicated server
Virtual server
$ paste a b
Unix Dedicated server
Linux Virtual server
Windows
$ paste -d"|" a b
Unix|Dedicated server
Linux|Virtual server
Windows|
$ paste –s a b
Unix Linux Windows
Dedicated server Virtual server
$ paste –s –d”,” a b
Unix,Linux,Windows
Dedicated server,Virtual server

23) more:- Displays text one screen at a time.


Syntax :- more [options] filename
Description :-
 More command displays its output a page at a time. For example we are having a

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

big file with thousands of records and we want to read that file then we should
use more command. Consider a file named employees then we will use following
command to read its contents a page at a time.

-c Clear screen before displaying.


-e Exit immediately after writing the last line of the last file in the argument list.
-n Specify how many lines are printed in the screen for a given file.
+n Starts up the file from the given number.
Example:-
$ more -c myfile.txt
 Clears the screen before printing the file .
$ more -3 myfile.txt
 Prints first three lines of the given file. Press Enter to display the file line by line.
$ more +/"hope" myfile.txt
 Display the contents of file myfile.txt, beginning at the first line containing the
string "hope".

24) cmp:- It compares two files and tells you which line numbers are different.
Syntax : - cmp [options..] file1 file2
Description :-
 Let’s create a file named os2. And use cmp command to compare os and os1files.
- c Output differing bytes as characters.
Print the byte number (decimal) and the differing byte values (octal) for each
-l
difference.
- s Prints nothing for differing files, return exit status only.
- c Output differing bytes as characters.
Example:-
$ cat file1
memory
process
files
$ cat > file2
memory
process
files mgmt
$ cmp file1 file2
File1 file2 differ: char 21, line 3
 The two files are compared byte by byte and the location of the first mismatch is
echoed to the screen. cmp doesn’t bother about possible subsequent mismatches.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

25) comm:- compare two sorted files line by line


Syntax:- comm [option]... FILE1 FILE2
Description :-
 Compare sorted files FILE1 and FILE2 line by line.
 Requires two sorted files and lists differing entries in different columns. produces
three text columns as output:
1 Lines only in file1.
2 Lines only in file2.
3 Lines in both files.
-1 suppress lines unique to FILE1
-2 suppress lines unique to FILE2
-3 suppress lines that appear in both files

 For example let’s create two files named file1 and file2 with following data.
$ cat > file1
c.k.shukla
chanchalsanghvi
s.n.dasgupta
sumit [1] + Stopped

$ cat > file2


anilaggarwal
barunsengupta
c.k.shukla
lalit
 Now let’s use comm. Command with these two files.
$ comm file1 file2
anilaggarwal
barunsengupta
c.k.shukla
chanchalsanghvi
lalit
s.n.dasgupta
sumit
 In the above output we can see that first column contains two lines unique to the
first file and second column contains three lines unique to the second file and the
third column contains two lines common to both the files. Comm. Can produce the

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

single column output using 3 options -1,-2 or -3. To drop a particular column,
simply use its column number as a prefix.

Example :-
$ cat file1
f1.c
f2.c
f3.c
f4.c
f5.c

$ cat file2
f1.c
f3.c
f4.c
f6.c
f7.c
 Now, When you run the comm command on these files, this is what you get:
$ comm file1 file2
f1.c
f2.c
f3.c
f4.c
f5.c
f6.c
f7.c
 The output is split in 3 columns. Column1 indicates files which are unique in file1,
column 2 indicates files unique to file2. Column 3 indicates files common between
them. comm command provides some real good options with which you can filter
the output better.
 Now, say you want to find out only the list of files which were there in the older
version but not in the newer version:
$ comm -23 file1 file2
f2.c
f5.c
 The option -23 indicates to remove the second and third columns from the comm
command output, and hence we are left with only the first column which is the
files unique in file1.
 Similarly, to find out the list of files which were not there in the old version, but
has been added in the new version:

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ comm -13 file1 file2


f6.c
f7.c
 As explained above, -13 option tells to remove the first and third columns from
the comm output.
 Finally, to know the list of files which have been retained, or common in both the
versions:
$ comm -12 file1 file2
f1.c
f3.c
f4.c
 When you apply comm command on files, the files should be sorted. This
command works only on sorted files.
26) diff:- It is used to find differences between two files.
Syntax :- diff [options..] fileone filetwo
Description :-
 Diff is the third command that can be used to display file differences. Unlike its
fellow members ,cmp and comm. , it also tells us which lines in one file have to be
changed to make the two files identical.
-b Ignore any changes which only change the amount of whitespace (such as
spaces or tabs).
-w Ignore whitespace entirely.
-B Ignore blank lines when calculating differences.
-y Display output in two columns.
-i Ignore changes in case.consider upper- and lower-case letters equivalent.
Example:-
$ cat 1.txt
aaa
bbb
ccc
ddd
eee
fff
ggg
$ cat 2.txt
bbb
cc
ddd
eee
fff

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

ggg
hhh
$ diff 1.txt 2.txt
1d0
< aaa
3c2
< ccc
---
>cc
7a7
> hhh
 Lines like "1d0" and "3c2" are the coordinates and types of the differences
between the two compared files, while lines like "< aaa" and "> hhh" are the
differences themselves.
 diff change notation includes 2 numbers and a character between them.
Characters tell you what kind of change was discovered:
 d – a line was deleted
 c – a line was changed
 a – a line was added
 Number to the left of the character gives you the line number in the original (first)
file, and the number to the right of the character tells you the line number in the
second file used in comparison.
 So, looking at the two text files and the diff output above, you can see what
happened:

1d0
< aaa
 This means that 1 line was deleted. < aaa suggests that the aaa line is present only
in the original file.
3c2
< ccc
---
>cc
 And this means that the line number 3 has changed. You can see how this
confirms that in the first file the line was "ccc", and in the second it now is "c c".
7a7
> hhh
 Finally, this confirms that one new line appeared in the second file, it's "hhh" in
the line number 7.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

27) chmod:- chmod command allows you to alter / Change access rights to files and
directories.
Syntax:- chmod [options] [MODE] FileName
Description :-
 chmod command is used to set the permissions of one or more files for all three
categories of users (user,group and others ). It can be run only by the user and
super user. Command can be used in two ways. Let’s first take a look at the
abbreviations used by chmod command.
Category Operation Permission
u User + Assigns permission r Read permission

g Group - Removes w Write permission


permission
o Others = Assigns absolute x Execute permission

File Permission :
# File Permission
0 none
1 execute only
2 write only
3 write and execute
4 read only
5 read and execute
6 read and write
7 set all permissions
Relative permissions
 When changing permissions in a relative manner, chmod only changes the
permissions specified in the command line and leaves the other permissions
unchanged. In this mode it uses the following syntax:
 let’s first check the permission of file shortlist. It shows read/write permission.
Let’s assign execute permission to this file for owner.
$ ls –l
-rw-r--r—1 shortlist None 241 Feb 21 04:02
$ chmod u+x shortlist
$ ls -l
-rwxr--r-- 1 shortlist None 241 Feb 21 04:02
 Here chmod uses expression u+x means – u shows user category that is user, +
shows we need to assign the permission and x shows execute permission.
Sameway we can assign other permissions.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

Absolute permissions
 Sometimes you don’t need to know what a file’s current permissions are, but want
to set all nine permission bits explicitly. The expression used by chmod here is a
string of three octal numbers. Each type of permission is assigned a number as
shown:
Read permission-4
Write permission-2
Execute permission -1
 For each category we add numbers that represent the assigned permission. For
instance , 6 represents read and write permission , and 7 represents all
permissions.
Example :
$ chmod 666 myfile or(chmod u=rw,g=rw,o=rwmyfile) shortlist
 Shows read and wrie (4 +2) permissions for all three types of users.

28) chown:- Command for system V that changes the owner of a file.
Syntax :- chown [options] newowner filename/directoryname
Description:-
Change the permission on files that are in the subdirectories of the directory that
-R
you are currently in.
-c Change the permission for each file.
Prevents chown from displaying error messages when it is unable to change the
-f
ownership of a file.
Example :-
$ ls -l demo.txt
-rw-r--r-- 1 root root 0 Jan 31 05:48 demo.txt
$ chownvivek demo.txt
-rw-r--r-- 1 vivek root 0 Jan 31 05:48 demo.txt

29) chgrp:- chgrp command is used to change the group of the file or directory. This is an
admin command. Root user only can change the group of the file or directory.
Syntax:- chgrp [options] newgroup filename/directoryname
Description:-
Change the permission on files that are in the subdirectories of the directory
-R
that you are currently in.
-c Change the permission for each file.
-f Force. Do not report errors.
Example :-
$ ls -l demo.txt
-rw-r--r-- 1 root root 0 Jan 31 05:48 demo.txt

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ chgrp vivek demo.txt


-rw-r--r-- 1 root vivek 0 Jan 31 05:48 demo.txt

30) file:- file command tells you if the object you are looking at is a file or a directory.
Syntax:- file [options] directoryname/filename
Description:-
 File command is used to determine the type of file, especially of an ordinary file.
We can use it with one or more filenames as arguments. For example we can use
file command to check the type of the os1 file that we have created.
$ file os1
os1: short english text

31) finger:- finger command displays the user's login name, real name, terminal name and
write status (as a ''*'' after the terminal name if write permission is denied), idle time,
login time, office location and office phone number.
Syntax:- finger [username]
Description :-
-l Force long output format
-s Force short output format
Example :-
$ finger rahul
Login: abc Name: (null)
Directory: /home/abc Shell: /bin/bash
On since Mon Nov 1 18:45 (IST) on :0 (messages off)
On since Mon Nov 1 18:46 (IST) on pts/0 from :0.0
New mail received Thu Feb 7 10:33 2015 (IST)
Unread since Mon Feb 8 12:59 2016 (IST)
No Plan.

32) sleep:- Delay for a specified amount of time


Syntax :- sleep NUMBER[SUFFIX]
Description:-
 The sleep command pauses for an amount of time defined by NUMBER.
 SUFFIX may be "s" for seconds (the default), "m" for minutes, "h" for hours, or "d"
for days.
Example :-
 To sleep for 5 seconds, use:
$ sleep 5
 To sleep for 2 minutes, use:

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ sleep 2m
 To sleep for 3 hours, use:
$ sleep 3h
 To sleep for 5 days, use:
$ sleep 5d

33) kill:- kill command is used to kill the background process.


Syntax:- kill [options] pid
Description :-
 The command kill sends the specified signal to the specified process or process
group.
 If no signal is specified, the TERM signal is sent. The TERM signal will kill processes
which do not catch this signal.
 For other processes, it may be necessary to use the KILL (9) signal, since this signal
cannot be caught.
pid. Specify the list of processes that kill should signal
-s send the specified signal to the process
-l list all the available signals.
-9 Force to kill a process.

34) users :- users command displays currently logged in users.


Syntax:- users
Output:-
$ users
dietstaff dietstaff

35) ps:- It is used to report the process status. ps is the short name for Process Status.
Syntax:- ps [options]

Description :-
-a List information about all processes most frequently requested: all those except
process group leaders and processes not associated with a terminal
-A List information for all processes. Identical to -e, below
-f Generate a full listing
-j Print session ID and process group ID
-l Generate a long listing
Example :-
$ps

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

PID TTY TIME CMD


291 console 0:00 bash

36) ln :- ln command is used to create link to a file (or) directory. It helps to provide soft link
for desired files.
Syntax:- ln [options] existingfile(or directory)name newfile(or directory)name
Description:-
What Is A Link?
 A link is an entry in your file system which connects a filename to the actual bytes
of data on the disk. More than one filename can "link" to the same data. Here's an
example. Let's create a file named file1.txt:
$ echo "This is a file." > file1.txt
 This command echoes the string "This is a file". Normally this would simply echo to
our terminal, but the > operator redirects the string's text to a file, in this case
file1.txt
 When this file was created, the operating system wrote the bytes to a location on
the disk and also linked that data to a filename, file1.txt so that we can refer to the
file in commands and arguments.
 If you rename the file, the contents of the file are not altered; only the
information that points to it.
 The filename and the file's data are two separate entities.

File1.txt

“This is a file””

 What the link command does is allow us to manually create a link to file data that
already exists.
 So, let's use link to create our own link to the file data we just created. In essence,
we'll create another file name for the data that already exists.
$ link file1.txt file2.txt
 The important thing to realize is that we did not make a copy of this data. Both
filenames point to the same bytes of data on the disk. Here's an illustration to help
you visualize it:

File1.txt File2.txt

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

“This is a file”

 If we change the contents of the data pointed to by either one of these files, the
other file's contents are changed as well. Let's append a line to one of them using
the >>operator:
$ echo "It points to data on the disk." >> file1.txt
 Now let's look at the contents of file1.txt:
$ cat file1.txt
This is a file.
 now let's look at the second file, the one we created with the link command.
$ cat file2.txt
This is a file.
 ln, by default, creates a hard link just like link does. So this ln command:
$ ln file1.txt file2.txt
 It is the same as the following link command. Because, both commands create a
hard link named file2.txt which links to the data offile1.txt.
$ link file1.txt file2.txt
 However, we can also use ln to create symbolic links with the -s option. So the
command:
$ ln -s file1.txt file2.txt
 It will create a symbolic link to file1.txt named file2.txt. In contrast to our hard link
example, here's an illustration to help you visualize our symbolic link:

File1.txt File2.txt

“This is a file””

 You should also be aware that, unlike hard links, removing the file (or directory)
that a symlink(symbolic linkl) points to will break the link. So if we create file1.txt:
$ echo "This is a file." > file1.txt
 Now, create a symbolic link to it:
$ ln -s file1.txt file2.txt
 we can cat either one of these to see the contents:

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ cat file1.txt
This is a file.
$ cat file2.txt
This is a file.
 But, if we remove file1.txt:
$ rm file1.txt
 we can no longer access the data it contained with our symlink:
$ cat file2.txt
cat: file2.txt: No such file or directory
-s Makes it so that it creates a symbolic link
-f If the destination file or files already exist, overwrite them.

37) head:- head command is used to display the first ten lines of a file, and also specifies how
many lines to display.
Syntax:- head [options] filename
Description:-
 Head command displays the top of the file. When used without an option , it
displays the first ten lines of the file.
-n To specify how many lines you want to display.
The number option-argument must be a decimal integer whose
-n number
sign affects the location in the file, measured in lines.
The number option-argument must be a decimal integer whose
-c number
sign affects the location in the file, measured in bytes.

Example :-
$ head myfile.txt
 Display the first ten lines of myfile.txt.
$ head -15 myfile.txt
 Display the first fifteen lines of myfile.txt.
$ head -c 20 myfile.txt
 Will output only the first twenty bytes (characters) of myfile.txt. Newlines count as
a single character, so if head prints out a newline, it will count it as a byte.
$ head -n 5K myfile.txt
 Displays the first 5,000 lines of myfile.txt.

38) tail:- tail command is used to display the last or bottom part of the file. By default it
displays last 10 lines of a file.
Syntax :- tail [options] filename
Description:-

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-l To specify the units of lines.


-b To specify the units of blocks.
-n To specify how many lines you want to display.
The number option-argument must be a decimal integer whose
-c number
sign affects the location in the file, measured in bytes.
The number option-argument must be a decimal integer whose
-n number
sign affects the location in the file, measured in lines.
Example : -
$ tail index.txt
 It displays the last 10 lines of 'index.txt'.
$ tail -2 index.txt
 It displays the last 2 lines of 'index.txt'.
$ tail -n 5 index.txt
 It displays the last 5 lines of 'index.txt'.
$ tail -c 5 index.txt
 It displays the last 5 characters of 'index.txt'.

39) sort:- It is used to sort the lines in a text file.


Syntax:- sort [options] filename
-b Ignores spaces at beginning of the line
-c Check whether input is sorted; do not sort
-r Sorts in reverse order
-u If line is duplicated only display once
-r Reverse the result of comparisons.

Example:-
$ cat > data.txt
apples
oranges
pears
kiwis
bananas
$ sort data.txt
apples
bananas
kiwis
oranges
pears
 Note that this command does not actually change the input file, data.txt. If you
want to write the output to a new file, output.txt, redirect the output like this:

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ sort data.txt > output.txt


 it will not display any output, but will create the file output.txt with the same
sorted data from the previous command. To check the output, use the cat
command:
$ cat output.txt
apples
bananas
kiwis
oranges
pears
 You can also use the built-in sort option -o, which allows you to specify an output
file:
$ sort -o output.txt data.txt
 Using the -o option is functionally the same as redirecting the output to a file;
neither one has an advantage over the other.
Sorting In Reverse Order :
 You can perform a reverse-order sort using the -r flag. For example, the following
command:
$ sort -r data.txt
pears
oranges
kiwis
bananas
apples
Checking For Sorted Order
 If you just want to check to see if your input file is already sorted, use the -c
option:
$ sort -c data.txt
 If your data is unsorted, you will receive an informational message reporting the
line number of the first unsorted data, and what the unsorted data is.

40) find:- Finds one or more files assuming that you know their approximate path.
Syntax :- find [options] path
Description :-
 Find is one of the powerful utility of Unix (or Linux) used for searching the files in a
directory hierarchy
path A path name of a starting point in the directory hierarchy
-maxdepth Descend at most levels (a non-negative integer) levels of directories
below the command line arguments.
-i ignore the case in the current directory and sub-directories.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-size Find file based on size


Example:-
$ find -name "sum.java"
./bkp/sum.java
./sum.java
$ find -iname "sum.java"
./SUM.java
./bkp/sum.java
./sum.java
$ find -maxdepth 1 -name "sum.java"
./sum.java
 Find Files Under Home Directory
 Find all the files under /home directory with name myfile.txt.
$ find /home -name myfile.txt
/home/myfile.txt
$ find . -size 10M
 Display files whose size is exactly 10M
$ find . -size +10M
 Display files larger than 10M size
$ find -newer "sum.java"
 Display the files which are modified after the modification of a give file.
$ find . -perm 777
 display the files based on the file permissions.
 This will display the files which have read, write, and execute permissions. To
know the permissions of files and directories use the command "ls -l".
$ find -name '*' -size +1000k
 The system would search for any file in the list that is larger than 1000k.

41) uniq:- Report or filter out repeated lines in a file.


Syntax:- uniq [option] filename
Description : -
-c Precede each output line with a count of the number of times the line
occurred in the input
-d Suppress the writing of lines that are not repeated in the input
-D Print all duplicate lines
-f Avoid comparing first N fields
-i Ignore case when comparing
-s Avoid comparing first N characters.
-u Prints only unique lines

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-w Compare no more than N characters in lines


Example:-
$ cat example.txt
Unix operating system
unix operating system
unix dedicated server
linux dedicated server
 The default behaviour of the uniq command is to suppress the duplicate line. Note
that, you have to pass sorted input to the uniq, as it compares only successive
lines.
$ uniq example.txt
unix operating system
unix dedicated server
linux dedicated server
 The -c option is used to find how many times each line occurs in the file. It prefixes
each line with the count.
$ uniq -c example.txt
2 unix operating system
1 unix dedicated server
1 linux dedicated server
 You can print only the lines that occur more than once in a file using the -d option.
$ uniq -d example.txt
unix operating system
 The -D option prints all the duplicate lines.
$ uniq -D example.txt
unix operating system
unix operating system

42) tr:- Translate characters.


Syntax:- tr [options] set1 [set2]
Description:-
-c Complement the set of characters specified by string1
-d Delete all occurrences of input characters that are specified by string1
-s replaces repeated characters listed in the string1 with single occurrence
Set1 First string or character to be changed
set2 Second string or character to change the string1
Example:-
 Convert lower case letters to upper case
 The following tr command translates the lower case letters to capital letters in the

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

give string:
$ echo "linux dedicated server" | tr "[:lower:]" "[:upper:]"
LINUX DEDICATED SERVER
$ echo "linux dedicated server" | tr "[a-z]" "[A-Z]"
LINUX DEDICATED SERVER
 The -c option is used to replace the non-matching characters with another set of
characters.
$ echo "unix" | tr -c "u" "a"
uaaa
 You can squeeze more than one occurrence of continuous characters with single
occurrence. The following example squeezes two or more successive blank spaces
into a single space.
$ echo "linux server" | tr -s " "
linux server
 The following example removes the word linux from the string.
$ echo "linuxserver" | tr -d "linux"
Server

43) history:- history command is used to list out the recently executed commands in the
number line order.
Syntax:- history [options]
Description:-
 The history command performs one of several operations related to recently-
executed commands recorded in a history list. Each of these recorded commands
is referred to as an ``event''.

-c clear the history list by deleting all of the entries.


Example :-
 To list the recently executed commands:
$ history
 This command is used to list the history.
To find specific command in history list:
$ history | grep cd
33 cd Pictures/
37 cd ..
39 cd Desktop/
61 cd /usr/bin/
68 cd
 This command is used to list only cd commands from history list.
To copy history list to file

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ history -a history.txt
 This command is used to copy history list to history.txt file .
To Clear all history:
$ history -c
 This command can be used to clear all history from history list.

44) write:- Send a message to another user.


Syntax:- write person [ttyname]
Description:-
 The write utility allows you to communicate with other users, by copying lines
from your terminal to theirs.
 When you run the write command, the user you are writing to gets a message of
the format:
Message from yourname@yourhost on yourtty at hh:mm ...
 Any further lines you enter will be copied to the specified user's terminal. If the
other user wants to reply, they must run write as well.
 When you are done, type an end-of-file or interrupt character. The other user will
see the message ‘EOF’ indicating that the conversation is over.
person If you wish to talk to someone on your own machine, then person is just the
person's login name. If you wish to talk to a user on another host, then
person is of the form 'user@host'.
ttyname If you wish to talk to a user who is logged in more than once, the ttyname
argument may be used to indicate the appropriate terminal name, where
ttyname is of the form 'ttyXX' or 'pts/X'.

45) grep:- It selects and prints the lines from a file which matches a given string or pattern.
Syntax:- grep [options] pattern [file]
Description:-
 This command searches the specified input fully for a match with the supplied
pattern and displays it.
 While forming the patterns to be searched we can use shell match characters, or
regular expressions.
 Let us begin with the simplest example of usage of grep.

-i Ignore case distinctions


-v Invert the sense of matching, to select non-matching lines.
-w Select only those lines containing matches that form whole words.
-x Select only matches that exactly match the whole line.
-c print a count of matching lines for each input file.
Example :-

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

$ grep "Error" logfile.txt


 This searches for the string "Error" in the log file and prints all the lines that has
the word "Error".
$ grep "string" file1 file2
 Searching for a string in multiple files.
$ grep -i "UNix" file.txt
 The -i option enables to search for a string case insensitively in the give file. It
matches the words like "UNIX", "Unix", "unix".
$ grep -w "world" file.txt
 By default, grep matches the given string/pattern even if it found as a substring in
a file. The -w option to grep makes it match only the whole words.
$ grep -c "sting" file.txt
 We can find the number of lines that matches the given string/pattern
$ grep -l "string" *
 We can just display the files that contain the given string/pattern.
$ grep -n "string" file.txt
 We can make the grep command to display the position of the line which contains
the matched string in a file using the -n option

46) pwd:-Displaying your current directory name (Print working directory).


Syntax:-pwd [options]
Description:-
 At the time of logging in user is placed in the specific directory of the file system.
You can move around from one directory to another, but any point of time, you
are located in only one directory. This directory is known as your current directory.
pwd command tells your current directory.
Example:-
$ pwd
/home/abc

47) wc:- Word Count (wc) command counts and displays the number of lines, words,
character and number of bytes enclosed in a file.
Syntax: - wc [options] [filename]
Description:-
 This command counts lines, words and characters depending on the options used.
It takes one or more filenames as its arguments and displays four-columnar
output. For example let’s read our os1 file. And we use wc command with that
filename.
-l print the newline counts.
-w print the word counts.

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

-c print the byte counts.


-m print the character counts.
-L print the length of the longest
line.

Example :-
$cat myfile.txt
Red Hat
CentOS
Fedora
Debian
Scientific Linux
OpenSuse
Ubuntu
Xubuntu
Linux Mint
Pearl Linux
Slackware
Mandriva
 The ‘wc‘ command without passing any parameter will display a basic result of
”myfile.txt‘ file. The three numbers shown below are 12 (number of lines), 16
(number of words) and 112 (number of bytes) of the file.
$wc myfile.txt
12 16 112 myfile.txt
 To count number of newlines in a file use the option ‘-l‘, which prints the number
of lines from a given file. Say, the following command will display the count of
newlines in a file. In the output the first filed assigned as count and second field is
the name of file.
$wc -l myfile.txt
12 myfile.txt
 Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a file. Type
the following command to count the words in a file.
$wc -w myfile.txt
16 myfile.txt
 When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of
bytes and characters respectively in a file.
$wc -c myfile.txt
112 myfile.txt
 The ‘wc‘command allow an argument ‘-L‘, it can be used to print out the length of

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

longest (number of characters) line in a file. So, we have the longest character line
(‘Scientific Linux‘) in a file.
$wc -L myfile.txt
16 myfile.txt

48) man:- man command which is short for manual, provides in depth information about the
requested command (or) allows users to search for commands related to a particular
keyword.
Syntax:- man commandname [options]
Description :-
-a Print a one-line help message and exit.
-k Searches for keywords in all of the manuals available.
Example:-
$ man mkdir
 Display the information about mkdir command

49) | (Pipeline command):- Used to combine more than one command. Takes output of 1st
command as input of 2nd command.
Syntax:- commmand1| command2|……
Example:-
$ls -l | grep "Feb"
-rw-r--r-- 1 dietstaffdietstaff 336 Feb 19 14:41 calc1.sh
-rw-r--r—1 dietstaffdietstaff 410 Feb 19 14:28 calc.sh
drwxr-xr-x 7 dietstaffdietstaff 4096 Feb 24 09:04 Desktop
drwxr-xr-x 7 dietstaffdietstaff 12288Feb 26 07:44 Downloads
drwxr-xr-x 3 dietstaffdietstaff 4096 Feb 26 08:55 lab
drwxr-xr-x 2 dietstaffdietstaff 4096 Feb 24 08:00 shellscript
-rw-r--r—1 dietstaffdietstaff 81 Feb 24 12:34 temp3.sh

Explain the basic system administration commands of unix


1) date : - Prints or sets the date and time.
Syntax :- date[options] [+format] [date]
Description :-
 Display the current date with current time, time zone.
 The command can also be used with suitable format specifies as arguments. Each
format is preceded by a + symbol, followed by the % operator, and a single
character describing the format.
Format
%a Abbreviated weekday(Tue).

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

%A Full weekday(Tuesday).
%b Abbreviated month name(Jan).
%B Full month name(January).
%c Country-specific date and time format..
%D Date in the format %m/%d/%y.
%j Julian day of year (001-366).
%p String to indicate a.m. or p.m.
%T Time in the format %H:%M:%S.
%t Tab space.
%V Week number in year (01-52); start week on Monday.
Example:-
$ date
Fri Feb 19 09:55:15 IST 2016
$ date +%m
02
$ date +%h
Feb
$ date +%y
16
$ date +"Date is %D %t Time is %T"
date is 19/02/16 Time is 10:52:34
 To know the week number of the year,
$ date -V
11
 To set the date,
$ date -s "10/08/2016 11:37:23"
 The above command will print Wed Oct 08 11:37:23 IST 2016
2) wall :- send a message to everybody's terminal.
Syntax :- wall [ message ]
 Wall sends a message to everybody logged in with their mesg(1) permission set to
yes. The message can be given as an argument to wall, or it can be sent to wall's
standard input. When using the standard input from a terminal, the message
should be terminated with the EOF key (usually Control-D).
 The length of the message is limited to 20 lines.
Example : -
$sudo wall message.txt
 Using the sudo command to run wall as the superuser, sends the contents
ofmessage.txt to all users.

ulimit : Setting limits on file size

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unix Commands

Syntax: - ulimit [limit]


Description :-
 The ulimit command imposes a restriction on the maximum size of the file that a
user is permitted to create , so that there is less wastage of disk space.
3) passwd:- It is used to change your password.
Syntax:- passwd
Description :-
 Passwd changes the password or shell associated with the user given by name or
the current user if name is omitted.
 First user has to insert current password. Then new password will be asked
followed by confirm new password field.
 passwd command can also be used to change the home directory where the path
stands for the home directory.
4) suid : - set user id.
Description :-
 suid (Set owner User ID up on execution) is a special type of file permissions given
to a file.
 Normally in Linux/Unix when a program runs, it inherits access permissions from
the logged in user.
 suid is defined as giving temporary permissions to a user to run a program/file
with the permissions of the file owner rather that the user who runs it.
 In simple words users will get file owner’s permissions as well as owner UID and
GID when executing a file/program/command.
Example:-
$ chmod u+s a.out
$ ls –l a.out
-rwsr-xr-rw 1 dietstaff dietstaff 121 Feb 21 11:18 a.out

Haresh Khachariya, Department CS&IT| – Operating System (2020-21)


Unit – 3 Shell Programming

1) Write a shell script to scans the name of the command and executes it.
Program :-
echo "enter command name"
read cmd
$cmd

Output :-
enter command name
cal
February 2016
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29

2) Write a shell script Which works like calculator and performs below operations Addition
, Subtract ,Division ,Multiplication
Program :-
i) using if..elif statement
echo " Enter one no."
read n1
echo "Enter second no."
read n2

echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
if [ $ch = "1" ]
then
sum=`expr $n1 + $n2`
echo "Sum ="$sum
elif [ $ch = "2" ]
then
sum=`expr $n1 - $n2`
echo "Sub = "$sum
elif [ $ch = "3" ]
then

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

sum=`expr $n1 \* $n2`


echo "Mul = "$sum
elif [ $ch = "4" ]
then
sum=`expr $n1 / $n2`
echo "Div = "$sum
fi

Output :-
Enter one no.
32
Enter second no.
12
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
2
Sub = 20

ii) using while loop and switch statement


i="y"
while [ $i = "y" ]
do
echo " Enter one no."
read n1
echo "Enter second no."
read n2
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
1) sum=`expr $n1 + $n2`
echo "Sum ="$sum;;
2)sum=`expr $n1 - $n2`
echo "Sub = "$sum;;
3)sum=`expr $n1 \* $n2`

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

echo "Mul = "$sum;;


4)sum=`expr $n1 / $n2`
echo "Div = "$sum;;
*)echo "Invalid choice";;
esac
echo "Do u want to continue ? y/n"
read i
if [ $i != "y" ]
then
exit
fi
done

Output :-
Enter one no.
32
Enter second no.
22
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
2
Sub = 10
Do u want to continue ? y/n
N

3) Write a shell script to print the pyramid structure for the given number.
Program :-
echo "enter the number"
read n
printf "\n"
for((i=1;i<=$n;i++))
do
for((j=1;j<=$i;j++))
do
printf "$j"
done
printf "\n"
done

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

Output :-
enter the number
4
1
12
123
1234

4) Write a shell script to find the largest among the 3 given numbers.
Program :-
clear
echo "Enter first number: "
read a
echo "Enter second number: "
read b
echo "Enter third number: "
read c

if [ $a -ge $b -a $a -ge $c ]
then
echo "$a is largest integer"
elif [ $b -ge $a -a $b -ge $c ]
then
echo "$b is largest integer"
elif [ $c -ge $a -a $c -ge $b ]
then
echo "$c is largest integer"
fi

Output :-
Enter first number:
22
Enter second number:
33
Enter third number:
42
44 is largest integer

5) Write a shell script to find factorial of given number n.


Program :-
clear

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

fact=1
echo "Enter number to find factorial : "
read n
a=$n
#if enter value less than 0
if [ $n -le 0 ]
then
echo "invalid number"
exit
fi
#factorial logic
while [ $n -ge 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "Factorial for $a is $fact"

Output :-
Enter number to find factorial :
5
Factorial for 5 is 120

6) Write a shell script to print all prime numbers from 1 to n.


Program :-
clear
echo "enter the range"
read n
echo "the prime no are:"
m=2
while [ $m -le $n ]
do
i=2
flag=0
while [ $i -le `expr $m / 2` ]
do
if [ `expr $m % $i` -eq 0 ]
then
flag=1
break
fi

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

i=`expr $i + 1`
done
if [ $flag -eq 0 ]
then
echo $m
fi
m=`expr $m + 1`
done

Output :-
enter the range
10
the prime no are
2
3
5
7

7) Write a shell script to reverse a number supplied by a user.


Program :-
if [ $# -eq 1 ]
then
if [ $1 -gt 0 ]
then
num=$1
sumi=0
while [ $num -ne 0 ]
do
lnum=`expr $num % 10`
sumi=`expr $sumi \* 10 + $lnum`
num=`expr $num / 10`
done
echo "Reverse of digits is $sumi of $1"
else
echo " Number is less than 0"
fi
else
echo "Insert only one parameter "
fi

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

Output :-
bash pr81.sh 123
Reverse of digits is 321 of 123

8) Write a shell script to find first n Fibonacci numbers like: 0 1, 1, 2, 3, 5, 13,…


Program :-
clear
echo "How many number of terms to be generated ?"
read n
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done

Output :-
How many numbers of terms to be generated?
5
Fibonacci Series up to 5 terms :
0
1
1
2
3

9) Write a shell script to check whether the given number is Perfect or not.
Program :-
echo Enter a number
read no
i=1
ans=0
while [ $i -le `expr $no / 2` ]

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

do
if [ `expr $no % $i` -eq 0 ]
then
ans=`expr $ans + $i`
fi
i=`expr $i + 1`
done
if [ $no -eq $ans ]
then
echo $no is perfect
else
echo $no is NOT perfect
fi

Output :-
Enter a number
6
6 is perfect

Enter a number
10
10 is NOT perfect

10) Write a shell script which displays a list of all files in the current directory to which you
have read, write and execute permissions
Program :-
for File in *
do
if [ -r $File -a -w $File -a -x $File ]
then
echo $File
fi
done

Output :-
Desktop
Documents
Downloads
lab
Music

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

Pictures
Public
shellscript
Templates
Videos

11) Write a shell script that deletes all the files in the current directory which are 0 bytes in
length.
Program :-
clear
find . -name "*" -size -1k –delete
echo “files deleted”

Output :-
files deleted

12) Write a shell script to check whether the given string is Palindrome or not.
Program :-
clear
echo "Enter the string:"
read str
echo
len=`echo $str | wc -c`
len=`expr $len - 1`
i=1
j=`expr $len / 2`
while test $i -le $j
do
k=`echo $str | cut -c $i`
l=`echo $str | cut -c $len`
if test $k != $l
then
echo "String is not palindrome"
exit
fi
i=`expr $i + 1`
len=`expr $len - 1`
done
echo "String is palindrome"

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

Output :-
Enter the string:
abba
String is palindrome

Enter the string:


abc
String is not palindrome

13) Write a shell script to display the digits which are in odd position in a given 5 digit
number
Program :-
echo "Enter a 5 digit number"
read num
n=1
while [ $n -le 5 ]
do
a=`echo $num | cut -c $n`
echo $a
n=`expr $n + 2`
done

Output :-
Enter a 5 digit number
12345
1
3
5

14) Write a shell script to check given year is leap year or not.
Program :-
clear
echo "enter any year"
read num
if [ `expr $num % 4` -eq 0 ]
then
if [ `expr $num % 100` -eq 0 -a `expr $num % 400` -ne 0 ]
then
echo "Not a leap year"
else
echo "Leap year "

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

fi
else
echo "Not a leap year"
fi

Output :-
enter any year
2016
Leap year

enter any year


2100
Not a leap year

15) Write a shell script to find the value of one number raised to the power of another.
Program :-
echo "Input number"
read no
echo "Input power"
read power
counter=0
ans=1
while [ $power -ne $counter ]
do
ans=`echo $ans \* $no | bc`
counter=`echo $counter + 1 | bc`
done
echo "$no power of $power is $ans"
Output :-
Input number
5
Input power
3
5 power of 3 is 125

16) Write a shell script to display the following details in a pay list Pay slip details, House
rent allowance, Dearness allowance, Provident fund. HRA is to be calculated at the rate
of 20% of basic, DA at the rate of 40% of basic and PF at the rate of 10% of basic.
Program :-

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

i="y"
while [ $i = "y" ]
do
echo "Please enter your Basic:"
read basic
echo "PAY SLIP DETAILS"
echo "1. HOUSE RENT ALLOWANCE"
echo "2. DEARNESS ALLOWANCE"
echo "3. PROVIDENT FUND"
echo "your choice:"
read ch
case $ch in
1) hra=`expr $basic \* 20 / 100`
echo Your HOUSE RENT ALLOWANCE is Rs. $hra;;
2) da=`expr $basic \* 40 / 100`
echo Your DEARNESS ALLOWANCE is Rs. $da;;
3) pf=`expr $basic \* 10 / 100`
echo Your PPOVIDENT FUND is Rs. $pf;;
*) echo "Not a valid choice";;
esac
echo "Do u want to continue ?"
read i
if [ $i != "y" ]
then
exit
fi
done

Output :-
Please enter your Basic:
1000
PAY SLIP DETAILS
1. HOUSE RENT ALLOWANCE
2. DEARNESS ALLOWANCE
3. PROVIDENT FUND
your choice:
1
Your HOUSE RENT ALLOWANCE is Rs. 200
Do u want to continue ?

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

17) Write a shell script to find sum of digits of a number.


Program :-
clear
echo "enter the number"
read n
sum=0
a=$n
while(($n >0))
do
x=`expr $n % 10`
sum=`expr $sum + $x`
n=`expr $n / 10`
done
echo "the sum of $a is $sum"
Output :-
enter the number
3355
the sum of 3355 is 16

18) Write a shell script that greets the user by saying Good Morning, Good Afternoon, and
Good Evening according to the system time.
Program :-
clear
#hours=`date|cut -c 12-13`
hours=`date +%H`
if [ $hours -le 12 ]
then
echo "Good Morning"
elif [ $hours -le 16 ]
then
echo "Good Afternoon"
elif [ $hours -le 20 ]
then
echo "Good Evening"
else
echo "Good Night"
fi

Output :-
Good Afternoon

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 3 Shell Programming

19) Write a shell script to generate mark sheet of a student. Take 3 subjects, calculate and
display total marks, percentage and Class obtained by the student.
Program :-
Clear
echo "Enter the five subject marks for the student"
read s1 s2 s3
sum1=`expr $s1 + $s2 + $s3`
echo "Sum of 5 subjects are: " $sum1
per=`expr $sum1 / 3`
echo " Percentage: " $per
if [ $per -ge 60 ]
then
echo "You get Distinction"
elif [ $per -ge 50 ]
then
echo “You get First class―
elif [ $per -ge 40 ]
then
echo "You get Second class"
else
echo "You get Fail"
fi

Output :-
Enter the five subject marks for the student
78 88 92
Sum of 5 subjects are: 258
Percentage: 86
You get Distinction

20) Write a shell script that finds total no. of users and finds out how many of them are
currently logged in.
Program :-
cat /etc/passwd>user.txt
set `wc -l user.txt`
log=`who|wc -l`
echo "There are $1 users in network "
echo "There are $log user loged in right now"
Output :-
There are 49 users in network
There are 2 user loged in right now

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Que-1 Installation and Configuration of Linux - Using with Ubuntu


 Here is official installation steps for ubuntu
https://ubuntu.com/tutorials/tutorial-install-ubuntu-desktop#1-overview
https://ubuntu.com/tutorials/tutorial-install-ubuntu-server#1-overview (server)

 steps for dual boot installation (How To Install Ubuntu18.04 LTS Alongside Windows 10)

step 1: Make a backup [optional]


It is always nice to make a back up, just in case if you mess up with the system. There are
numerous articles on the web to show you how to backup your system.
Step 2: Create a live USB/disk of Ubuntu
The next thing you need to do is to create a live USB or disk. I recommend Universal USB
Installer to create a live USB of Linux OS in Windows
Read this screenshot tutorial on: how to create a live USB of Ubuntu Linux in Windows
Step 3: Make a partition where Ubuntu will be installed
If you have just one partition like this, you need to make some free space out of it for Linux. If you
have several partitions of considerable size, use any of them except C drive because it may erase
the data
To make a partition in Windows 8, go to Disk Management tool. You can find disk management
tool by searching for ‘disk’ in Control Panel.

In the Disk Management tool, right click on the drive which you want to partition and
select shrink volume. In my case, I shrank the C drive to make some free space:

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Or if you have free space in your drive make it is not a window drive then delete particular volume

You can leave the free space as it is. We shall use it while installing Ubuntu.

Step 4: Disable fast startup in Windows [optional]


Windows 8 introduced a new feature called “fast startup” for quick boot. While it is not
mandatory, it would be better to have it disabled.
Go to Control Panel > Hardware and Sound > Power Options > System Settings > Choose what the
power buttons do and uncheck the Turn on fast startup box

Step 5: Disable secure boot in Windows 10 and 8.1

This is the most important step. The new secure boot feature of Windows 8, originally intended
for security feature for root kit viruses, prevents dual booting of Windows with Linux. To dual
boot Windows 8 with Linux, we must disable secure boot in UEFI.

Step 6: Installing Ubuntu along with Windows 10, 8.1

you have booted in the live USB, you will be presented with option to try or install Ubuntu.
You can also boot from any bootable media now you are entering in installation steps of ubuntu

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Step 7 :select language option and click on install button

Step 8: Prepare to install Ubuntu

 you will first be asked to select your keyboard layout After selecting Continue you will be
asked What apps would you like to install to start with?
o The two options are ‘Normal installation’ and ‘Minimal installation’.
 The first is the equivalent to the old default bundle of utilities, applications, games and media
players — a great launchpad for any Linux installation.
 The second takes considerably less storage space and allows you to install only what you need.
Beneath the installation-type question are two checkboxes; one to enable updates while
installing and another to enable third-party software.
 We advise enabling both Download updates and Install third-party software.
 Stay connected to the internet so you can get the latest updates while you install Ubuntu.
 If you are not connected to the internet, you will be asked to select a wireless network, if available.
We advise you to connect during the installation so we can ensure your machine is up to date

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Step 9 : installation type:


The main screen which you should pay attention to is Installation Type. Choose Something
else here:

Remember we had created some free space beforehand? We shall use the free space to create
Root, Swap and Home. Select the free space and click on the + sign to create partition .

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

It will provide you with option to create Linux partition. We are creating the Root partition. Any
thing above 20 GB is more than sufficient for it. Choose the size, select Ext 4 as file type and /
(means root) as the mount point.there basic three partition root , boot and swap area

Clicking on OK in previous step will bring you to the partition screen. Next we will create swap.
Like previously, click on the + sign again. This time use the file type as Swap area. Suggestible
swap size is double of RAM

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

In similar fashion, boot and then create a Home partition. Allocate it maximum space (in fact
allocate it rest of the free space) because this is where you’ll save music, pictures and
downloaded files.

Once you are ready with Root, Swap and Home, click on Install Now:

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Step 10 Select Your Time zone:

Step 11 Provide your User Credentials


In the next screen you will be prompted to provide your user credentials. In this screen
provide your name, computer name, username and the password to login into Ubuntu
18.04 LTS

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Step 12 Start Installing Ubuntu 18.04 LTS:


The installation of Ubuntu 18.04 LTS starts now and will take around 5-10 mins depending
on the speed of your computer,

Step 13 Restart Your System:


Once the installation is completed, remove the USB/DVD from the drive and Click “Restart
Now” to restart your system

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
Step:14 Login to Your Ubuntu 18.04 desktop
Once your system has been rebooted after the installation then you will get the beneath
login screen, enter the User name and password that you have set during installation (St

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Que -2 Add a new user account


 You can add multiple user accounts to your computer. Give one account to each person in your
household or company. Every user has their own home folder, documents, and settings.
You need administrator privileges to add user accounts.
1. Open the Activities overview and start typing Users.
2. Click on Users to open the panel.
3. Press Unlock in the top right corner and type in your password when prompted.
4. Press the + button, below the list of accounts on the left, to add a new user account.
5. If you want the new user to have administrative access to the computer, select Administrator for the
account type.
Administrators can do things like add and delete users, install software and drivers, and change the
date and time.
6. Enter the new user’s full name. The username will be filled in automatically based on the full name. If
you do not like the proposed username, you can change it.
7. You can choose to set a password for the new user, or let them set it themselves on their first login.
If you choose to set the password now, you can press the icon to automatically generate a random
password.
8. Click Add.

Screen :

 Open Terminal by pressing Crtl+Alt+T or Search 'Terminal' in Dash.


 Execute the following command in terminal
 sudo apt-get install gnome-system-tools
 Search "Users" in Dash

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

 Click and it will run the Users and Groups :

 Click Add Button to add new user

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

 Steps to Create a New Sudo User command line:

 Log in to your server as the root user.


 Use the adduser command to add a new user to your system.
 #adduser username
 Set and confirm the new user's password at the prompt. A strong password is highly recommended!
 Set password prompts:
 Enter new UNIX password:
 Retype new UNIX password:
 passwd: password updated successfully
 User information prompts:
 Changing the user information for username Enter the new value, or press ENTER for the default Full
Name []:
 Room Number []:
 Work Phone []:
 Home Phone []:
 Other []:
 Is the information correct? [Y/n]

Que-3 Install / Uninstall Software

 Terminal:

 # sudo apt-get install pakege _name


 #sudo apt-get remove pakege_name

 GUI:
Install additional applications
 An application is software that has a graphical user interface (GUI). The Ubuntu development
team has chosen a default set of applications that we think makes Ubuntu very useful for most
day-to-day tasks. However, you will certainly want to install more applications to make
Ubuntu more useful to you. To install an application, you can use Ubuntu Software.
 Applications are available in two formats: snap packages and Debian packages. An application
available as a snap package is from now on referred to as a snap. Some applications are
available in both formats. In such a case in Ubuntu Software the snap will be listed first.
You may also wish to install software that does not have a GUI. To install such software, you
can use Synaptic. Note that Synaptic does not list snaps.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

 To install an application:
1. Click the Ubuntu Software icon in the Dock, or search for Software in the Activities search bar.
2. When Ubuntu Software launches, search for an application, or select a category and find an
application from the list.
3. Select the application that you want to install and click Install.
4. You will be asked to authenticate by entering your password. Once you have done that the
installation will begin. The installation usually finishes quickly, but could take a while if you have a
slow Internet connection.

 To Remove an application
 An application is software that has a graphical user interface (GUI). You can use Ubuntu
Software to remove applications that you no longer use.
 Applications are available in two formats: snap packages and Debian packages. An application
available as a snap package is from now on referred to as a snap. Some applications are
available in both formats. In such a case in Ubuntu Software the snap will be listed first.
 You may also wish to remove software that does not have a GUI. To remove such software,
you can use Synaptic. Note that Synaptic does not list snaps.
 To remove an application:
1. Click the Ubuntu Software icon in the Dock, or search for Software in the Activities search bar.
2. When Ubuntu Software opens, click the Installed button at the top.
3. Find the application that you want to remove by using the search box or by looking through
the list of installed applications.
4. Select the application and click Remove.
5. Confirm that you want to remove the application.
6. You will be asked to authenticate by entering your password. After you have done that, the
application will be removed.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
Que-4 FTP Server:
 File Transfer Protocol (FTP) is a TCP protocol for uploading and downloading files between
computers. FTP works on a client/server model.
 The server component is called an FTP daemon.
 It continuously listens for FTP requests from remote clients.
 When a request is received, it manages the login and sets up the connection. For the duration of
the session it executes any of commands sent by the FTP client

o Access to an FTP server can be managed in two ways:


 Anonymous
 Authenticated

 In the Anonymous mode, remote clients can access the FTP server by using the default user account
called “anonymous” or “ftp” and sending an email address as the password.
 In the Authenticated mode a user must have an account and a password. This latter choice is very
insecure and should not be used except in special circumstances. If you are looking to transfer files
securely see SFTP in the section on OpenSSH-Server.
 User access to the FTP server directories and files is dependent on the permissions defined for the
account used at login. As a general rule, the FTP daemon will hide the root directory of the FTP server and
change it to the FTP Home directory. This hides the rest of the file system from remote sessions.

o vsftpd - FTP Server Installation


 vsftpd is an FTP daemon available in Ubuntu. It is easy to install, set up, and maintain. To
install vsftpd you can run the following command:
sudo apt install vsftpd

o Anonymous FTP Configuration


 By default vsftpd is not configured to allow anonymous download. If you wish to enable
anonymous download edit /etc/vsftpd.conf by changing:

anonymous_enable=YES

 During installation a ftp user is created with a home directory of /srv/ftp. This is the
default FTP directory.
 If you wish to change this location, to /srv/files/ftp for example, simply create a directory
in another location and change the ftp user’s home directory:

sudo mkdir -p /srv/files/ftp


sudo usermod -d /srv/files/ftp ftp
 After making the change restart vsftpd:

sudo systemctl restart vsftpd.service\


 Finally, copy any files and directories you would like to make available through
anonymous FTP to /srv/files/ftp, or /srv/ftp if you wish to use the default.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

 User Authenticated FTP Configuration


 By default vsftpd is configured to authenticate system users and allow them to download
files. If you want users to be able to upload files, edit /etc/vsftpd.conf:

write_enable=YES
 Now restart vsftpd:

sudo systemctl restart vsftpd.service


 Now when system users login to FTP they will start in their home directories where they
can download, upload, create directories, etc.
 Similarly, by default, anonymous users are not allowed to upload files to FTP server. To
change this setting, you should uncomment the following line, and restart vsftpd:

anon_upload_enable=YES

 To configure FTPS, edit /etc/vsftpd.conf

Que-5 Domain Name Service (DNS)


 Domain Name Service (DNS) is an Internet service that maps IP addresses and fully
qualified domain names (FQDN) to one another. In this way, DNS alleviates the
need to remember IP addresses.
 Computers that run DNS are called name servers. Ubuntu ships with BIND (Berkley
Internet Naming Daemon), the most common program used for maintaining a
name server on Linux.
Installation
At a terminal prompt, enter the following command to install dns:
sudo apt install bind9

A very useful package for testing and troubleshooting DNS issues is the dnsutils package. Very often these tools
will be installed already, but to check and/or install dnsutils enter the following:
sudo apt install dnsutils

Configuration
There are many ways to configure BIND9. Some of the most common configurations are a caching nameserver,
primary server, and secondary server.
 When configured as a caching nameserver BIND9 will find the answer to name queries and remember
the answer when the domain is queried again.
 As a primary server, BIND9 reads the data for a zone from a file on its host and is authoritative for that
zone.
 As a secondary server, BIND9 gets the zone data from another nameserver that is authoritative for the
zone.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

Overview
The DNS configuration files are stored in the /etc/bind directory. The primary configuration file
is /etc/bind/named.conf, which in the layout provided by the package just includes these files.
 /etc/bind/named.conf.options: global DNS options
 /etc/bind/named.conf.local: for your zones
 /etc/bind/named.conf.default-zones: default zones such as localhost, its reverse, and the root hints

Caching Nameserver
The default configuration acts as a caching server. Simply uncomment and edit /etc/bind/named.conf.options to
set the IP addresses of your ISP’s DNS servers

Primary Server

In this section BIND9 will be configured as the Primary server for the domain example.com. Simply
replace example.com with your FQDN (Fully Qualified Domain Name).

Secondary Server

Once a Primary Server has been configured a Secondary Server is highly recommended in order to maintain the
availability of the domain should the Primary become unavailable.

First, on the Primary server, the zone transfer needs to be allowed. Add the allow-transfer option to the example
Forward and Reverse zone definitions in /etc/bind/named.conf.local

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
Que-6 How to Configure Ubuntu’s Built-In Firewall

 Ubuntu includes its own firewall, known as ufw – short for “uncomplicated firewall.” Ufw is an easier-to-
use frontend for the standard Linux iptables commands. You can even control ufw from a graphical
interface.
 Ubuntu’s firewall is designed as an easy way to perform basic firewall tasks without learning iptables. It
doesn’t offer all the power of the standard iptables commands, but it’s less complex.

 Terminal Usage

 The firewall is disabled by default. To enable the firewall, run the following command from a terminal:

sudo ufw enable

 You don’t necessarily have to enable the firewall first. You can add rules while the firewall is offline, and
then enable it after you’re done configuring it.

 To open a port (SSH in this example):

 sudo ufw allow 22


 Rules can also be added using a numbered format:
 sudo ufw insert 1 allow 80
 Similarly, to close an opened port:

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
 sudo ufw deny 22
 To remove a rule, use delete followed by the rule:
 sudo ufw delete deny 22
 It is also possible to allow access from specific hosts or networks to a port. The following example allows
SSH access from host 192.168.0.2 to any IP address on this host:
 sudo ufw allow proto tcp from 192.168.0.2 to any port 22
Replace 192.168.0.2 with 192.168.0.0/24 to allow SSH access from the entire subnet.

 ufw can be disabled by:

 sudo ufw disable


 To see the firewall status, enter:

sudo ufw status


Logging is disabled by default, but you can also enable logging to print firewall messages to the system
log:

sudo ufw logging on

 GUFW Graphical Interface

 UFW is a graphical interface for ufw. Ubuntu doesn’t come with a graphical interface, but
gufw is included in Ubuntu’s software repositories. You can install it with the following
command:

sudo apt-get install gufw

 GUFW appears in the Dash as an application named Firewall Configuration. Like ufw itself,
GUFW provides a simple, easy-to-use interface. You can easily enable or disable the
firewall, control the default policy for inbound or outbound traffic, and add rules.

 The rules editor can be used to add simple rules or more complicated ones.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

 Remember, you can’t do everything with ufw – for more complicated firewall tasks, you’ll
have to get your hands dirty with iptables.

Que-7 Web Servers:

 A Web server is a software responsible for accepting HTTP requests from clients, which
are known as Web browsers, and serving them HTTP responses along with optional data
contents, which usually are Web pages such as HTML documents and linked objects
(images, etc.).

 HTTPD - Apache2 Web Server

 Apache is the most commonly used Web server on Linux systems. Web servers are used to
serve Web pages requested by client computers. Clients typically request and view Web
pages using Web browser applications such as Firefox, Opera, Chromium, or Internet
Explorer.
 Users enter a Uniform Resource Locator (URL) to point to a Web server by means of its
Fully Qualified Domain Name (FQDN) and a path to the required resource. For example, to
view the home page of the Ubuntu Web site a user will enter only the FQDN:

www.ubuntu.com

 To view the community sub-page, a user will enter the FQDN followed by a path:
www.ubuntu.com/community

 The most common protocol used to transfer Web pages is the Hyper Text Transfer Protocol (HTTP).
Protocols such as Hyper Text Transfer Protocol over Secure Sockets Layer (HTTPS), and File Transfer
Protocol (FTP), a protocol for uploading and downloading files, are also supported.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
 Apache Web Servers are often used in combination with the MySQL database engine, the HyperText
Preprocessor (PHP) scripting language, and other popular scripting languages such as Python and Perl.
This configuration is termed LAMP (Linux, Apache, MySQL and Perl/Python/PHP) and forms a powerful
and robust platform for the development and deployment of Web-based applications.

Installation
The Apache2 web server is available in Ubuntu Linux. To install Apache2:
 At a terminal prompt enter the following command:

 sudo apt install apache2

Configuration
Apache2 is configured by placing directives in plain text configuration files. These directives are separated
between the following files and directories:
1. apache2.conf: the main Apache2 configuration file. Contains settings that are global to Apache2.

2. httpd.conf: historically the main Apache2 configuration file, named after the httpd daemon. Now the file
does not exist. In older versions of Ubuntu the file might be present, but empty, as all configuration
options have been moved to the below referenced directories.

3. conf-available: this directory contains available configuration files. All files that were previously
in /etc/apache2/conf.d should be moved to /etc/apache2/conf-available.
4. conf-enabled: holds symlinks to the files in /etc/apache2/conf-available. When a configuration file is
symlinked, it will be enabled the next time apache2 is restarted.

5. envvars: file where Apache2 environment variables are set.

6. mods-available: this directory contains configuration files to both load modules and configure them. Not
all modules will have specific configuration files, however.

7. mods-enabled: holds symlinks to the files in /etc/apache2/mods-available. When a module configuration


file is symlinked it will be enabled the next time apache2 is restarted.

8. ports.conf: houses the directives that determine which TCP ports Apache2 is listening on.

9. sites-available: this directory has configuration files for Apache2 Virtual Hosts. Virtual Hosts allow Apache2
to be configured for multiple sites that have separate configurations
.
10. sites-enabled: like mods-enabled, sites-enabled contains symlinks to the /etc/apache2/sites-
available directory. Similarly when a configuration file in sites-available is symlinked, the site configured by
it will be active once Apache2 is restarted.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
11. magic: instructions for determining MIME type based on the first few bytes of a file..
In addition, other configuration files may be added using the Include directive, and wildcards can be used to
include many configuration files. Any directive may be placed in any of these configuration files. Changes to the
main configuration files are only recognized by Apache2 when it is started or restarted .

Method-2 for LAMP and individual

 $ Sudo apt-get update (First time after installation)


 $ sudo apt-get install apache2
 $ sudo apt-get install phpmyadmin
 $ sudo apt-get install mysql-server
 Go to browser: http://localhost or
 http://127.0.1.1 (Home page)
 Store your demo.php page at /var/www

Now run http://localhost/demo.php

 Another way to Install apache web server, phpmyadmin and MySQL:


 $ sudo apt-get install tasksel (if not installed)
 $ sudo tasksel
 Choose LAMP server and press ok
 LAMP : L-Linux

A- Apache

M-MySQL

P-phpmyadmin

 Run services of Apache and then run php file


 $ sudo service apache2 start

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
Que-8 Samba Server

 This section of the Ubuntu Server Guide introduces principles and tools used in configuring your Ubuntu
Server for sharing network resources with Windows computers

 Successfully networking your Ubuntu system with Windows clients involves providing and integrating
with services common to Windows environments. Such services assist the sharing of data and
information about the computers and users involved in the network, and may be classified under three
major categories of functionality:
1. File and Printer Sharing Services. Using the Server Message Block (SMB) protocol to facilitate the sharing
of files, folders, volumes, and the sharing of printers throughout the network.
2. Directory Services. Sharing vital information about the computers and users of the network with such
technologies as the Lightweight Directory Access Protocol (LDAP) and Microsoft Active Directory®.
3. Authentication and Access. Establishing the identity of a computer or user of the network and
determining the information the computer or user is authorized to access using such principles and
technologies as file permissions, group policies, and the Kerberos authentication service.

File Server
 One of the most common ways to network Ubuntu and Windows computers is to configure Samba as a
File Server. This section covers setting up a Samba server to share files with Windows clients.

Installation
 The first step is to install the samba package. From a terminal prompt enter:

sudo apt install samba

Configuration
 The main Samba configuration file is located in /etc/samba/smb.conf. The default configuration file has a
significant number of comments in order to document various configuration directives.
1. First, edit the following key/value pairs in the [global] section of /etc/samba/smb.conf:
workgroup = EXAMPLE
...
security = user

The security parameter is farther down in the [global] section, and is commented by default. Also,
change EXAMPLE to better match your environment.
2. Create a new section at the bottom of the file, or uncomment one of the examples, for the directory to be
shared:
[share]
comment = Ubuntu File Server Share
path = /srv/samba/share
browsable = yes[OK TO YES FOR PRINTER]

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
guest ok = yes[printer ok TO YES]
read only = no
create mask = 0755

1. comment: a short description of the share. Adjust to fit your needs.


2. path: the path to the directory to share.
This example uses /srv/samba/sharename because, according to the Filesystem Hierarchy Standard
(FHS), /srv is where site-specific data should be served. Technically Samba shares can be placed
anywhere on the filesystem as long as the permissions are correct, but adhering to standards is
recommended.
3. browsable: enables Windows clients to browse the shared directory using Windows Explorer.
4. guest ok: allows clients to connect to the share without supplying a password.
5. read only: determines if the share is read only or if write privileges are granted. Write privileges are
allowed only when the value is no, as is seen in this example. If the value is yes, then access to the share
is read only.
6. create mask: determines the permissions new files will have when created.

3.Now that Samba is configured, the directory needs to be created and the permissions changed. From a
terminal enter:
sudo mkdir -p /srv/samba/share
sudo chown nobody:nogroup /srv/samba/share/

 Finally, restart the samba services to enable the new configuration:

 After editing smb.conf restart Samba:


sudo systemctl restart smbd.service nmbd.service

 From a Windows client you should now be able to browse to the Ubuntu file server and see the
shared directory. If your client doesn't show your share automatically, try to access your server by
its IP address, e.g. \\192.168.1.1 OR 127.0.0.1 , in a Windows Explorer window. To check
that everything is working try creating a directory from Windows.
 To create additional shares simply create new [dir] sections in /etc/samba/smb.conf, and
restart Samba. Just make sure that the directory you want to share actually exists and the
permissions are correct.

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
Que-9 Why use Wine:
 With the increasing popularity of Linux desktops, There is another requirement occurred that we should
have an application which can be used to run windows applications. Windows has a long list of beautiful
applications for users which is not available for Linux users. As we know that Linux does not support
windows executable so WineHQ is a solution to run windows applications and Linux systems.

This article will help you to install Wine 1.7.38 Development Release on RHEL based systems.
For ubuntu you have to use “apt-get “

Installing Prerequisite
 Wine required many development packages, So we need to install required packages for Wine using yum
package manager using following commands.

# yumgroupinstall 'Development Tools'

# yum install libX11-devel freetype-develzlib-devellibxcb-devel

Install Wine
 RPM packages for wine are not available for latest versions, So we need to download wine source code.
Use below commands to download it.

# cd /usr/src

# wget http://prdownloads.sourceforge.net/wine/wine-1.7.38.tar.bz2

# tar xjf wine-1.7.38.tar.bz2

# cd wine-1.7.38

 Configure wine using one of following command based on your system architecture.

For 32-Bit Systems:

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)

# ./configure

For 64-Bit Systems:

# ./configure --enable-win64

 Finally compile wine source with make command

# make

# make install

Check Wine Version

 Use following command to check version of wine installed on your system

On 32-Bit Systems:

# wine --version

On 64-Bit Systems:

# wine64 –version

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Unit – 4,5Getting Started with Linux (ubuntu)
How to Use Wine

 To use wine we need to login on GUI desktop. After that Download a windows executable (.exe) file
like PuTTY on your system and open it with Wine as below screenshot or use following command.

# wine putty.exe

Haresh Khachariya Dept:CS&IT|Operating System (2020-21)


Virtualization Concepts

(1) What is virtualization? Explain in details.


 Virtualization is the process of creating a software-based, or virtual,
representation of something, such as virtual applications, servers, storage and
networks.
 It is the single most effective way to reduce IT expenses while boosting efficiency
and agility for all size businesses.
 Operating system based Virtualization refers to an operating system feature in which
the kernel enables the existence of various isolated user-space instances.
 The installation of virtualization software also refers to Operating system-based
virtualization.
 It is installed over a pre-existing operating system and that operating system is
called the host operating system.
 In this virtualization, a user installs the virtualization software in the operating
system of his system like any other program and utilize this application to operate
and generate various virtual machines.
 The virtualization software allows direct access to any of the created virtual machine
to the user.
 As the host OS can provide hardware devices with the mandatory support, operating
system virtualization may affect compatibility issues of hardware even when the
hardware driver is not allocated to the virtualization software.
 Virtualization software is able to convert hardware IT resources which require
unique software for operation into virtualized IT resources.
 As the host OS is a complete operating system in itself, many OS based services are
available as organizational management and administration tools can be utilized for
the virtualization host management.
Full Virtualization:
 Virtual machine simulates hardware to allow an unmodified guest OS to be run in
isolation.
 There is two type of Full virtualizations in the enterprise market.
 On both full virtualization types, guest operating system’s source information will
not be modified.
1. Software assisted full virtualization
2. Hardware-assisted full virtualization
 It is also referred as true or pure virtualization.
 It completely relies on binary translation to trap and virtualize the execution of
sensitive, non-virtualizable instructions sets.

Haresh Khachariya Department CS&IT | – Operating System (2020-21)


Virtualization Concepts

 It emulates the hardware using the software instruction sets.


 Due to binary translation, it often criticized for performance issue.
Uses of OS Virtualization
 Used for virtual hosting environment.
 Used for securely allocation of finite hardware resources among a large number of
distrusting users.
 System administrator uses it to integrate server hardware by moving services on
separate hosts.
 To improvised security by separating several applications to several containers.
 These forms of virtualization don't require hardware to work efficiently.
Benefits of Virtualization:
 Reduced capital and operating costs.
 Increased IT productivity, efficiency, agility and responsiveness.
 Faster provisioning of applications and resources.
 Greater business continuity.
 Simplified data centre management.

Figure 1-1. Virtualization

Haresh Khachariya Department CS&IT | – Operating System (2020-21)


Virtualization Concepts

How OS Virtualization Works


 The steps for how these virtualization works are listed below:
 Connect to OS Virtualization Server
 Connect to virtual disk
 Then connect this virtual disk to the client
 OS is streamed to the client

(2) Virtual Machine

 Virtualization technology enables a single PC or server to simultaneously run


multiple operating systems or multiple sessions of a single OS
 A machine with virtualization software can host numerous applications, including
those that run on different operating systems, on a single platform
 The host operating system can support a number of virtual machines, each of which
has the characteristics of a particular OS
 The solution that enables virtualization is a virtual machine monitor (VMM), or
hypervisor
 Virtual machines are divided in two categories based on their use and correspondence
to real machine.
 System virtual machines: It provides a complete system platform that executes
complete operating system.
 Process virtual machines: It will run a single program.

Figure 1-2. Virtual Machine

Haresh Khachariya Department CS&IT | – Operating System (2020-21)


Virtualization Concepts

 When we run different processes on an operating system, it creates an illusion that


each process is running on a different processor having its own virtual memory, with
the help of CPU scheduling and virtual-memory techniques.
 There are additional features of a process that cannot be provided by the hardware
alone like system calls and a file system.
 The virtual machine approach does not provide these additional functionalities but
it only provides an interface that is same as basic hardware.
 Each process is provided with a virtual copy of the underlying computer system.
 We can create a virtual machine for several reasons, all of which are fundamentally
related to the ability to share the same basic hardware yet can also support different
execution environments, i.e., different operating systems simultaneously.
 The main drawback with the virtual-machine approach involves disk systems. Let
us suppose that the physical machine has only three disk drives but wants to support
seven virtual machines.
 Obviously, it cannot allocate a disk drive to each virtual machine, because virtual-
machine software itself will need substantial disk space to provide virtual memory
and spooling. The solution is to provide virtual disks.
 Users are thus given their own virtual machines. After which they can run any of
the operating systems or software packages that are available on the underlying
machine.
 The virtual-machine software is concerned with multi-programming multiple virtual
machines onto a physical machine, but it does not need to consider any user-support
software.
 This arrangement can provide a useful way to divide the problem of designing a
multi-user interactive system, into two smaller pieces.
Example:
 This is ideal for testing out other operating systems, like Windows 10 or alternative
Linux operating systems.
 You can also use virtual machines to run software on operating systems it wasn’t
designed for.
 For example, you can run Windows programs on a Mac or run multiple copies of an
app on a Mac with a virtual machine.
VM Advantages:
 Multiple OS environments can exist simultaneously on the same machine, separate
from each other;

Haresh Khachariya Department CS&IT | – Operating System (2020-21)


Virtualization Concepts

 Virtual machine can offer an instruction set architecture that differs from real
computer.
 Easy maintenance, application provisioning, availability and convenient recovery.
VM Dis-advantages:
 When multiple virtual machines are simultaneously running on a host computer,
each virtual machine may introduce an unstable performance, which depends on the
workload on the system by other running virtual machines.
 Virtual machine is not that much efficient as a real one when accessing the hardware.

(3) Explain virtual machine application.

 Virtual Machine isolates the hardware of our computer such as CPU, hard drives,
memory, NIC (Network Interface Card) etc, into many different execution
environments as per our requirements, feel like a single computer.
 Examples: VirtualBox, VMWare Workstation & Microsoft Hyper-V.

VirtualBox VMWare Workstation Microsoft Hyper - V


VirtualBox
 VirtualBox is a great, open-source application that runs on Windows, macOS, and
Linux.
 One of the best parts about VirtualBox is that there’s no commercial version.
 This means you get all features for free, including advanced features like
snapshots.
 This allows you to save a virtual machine’s state and revert to that state in the
future, which is great for testing.
VMWare Workstation

Haresh Khachariya Department CS&IT | – Operating System (2020-21)


Virtualization Concepts

 VMware Workstation allows for the installation of multiple instances of different


operating systems, including client and server operating systems.
 It helps the network or system administrators to check, test and verify the client
server environment.
 Administrator can also switch between different virtual machines at same time.
 VMware Workstation has its limitations, including hardware support, operating
system issues, and network protocols hurdles.
Microsoft Hyper - V
 Hyper-V is virtualization software that virtualizes software.
 It can not only virtualize operating systems but also entire hardware components,
such as hard drives and network switches. Unlike VirtualBox.
 Hyper-V is not limited to the user’s device. You can use it for server virtualization.
 Hyper-V is available in three versions.
1. Hyper-V for Windows Servers
2. Hyper-V Servers
3. Hyper-V on Windows 10

(4) Use of Virtual Machine

 Take trial on newer versions of operating systems


 Virtualization from your own desktop
 Test with different operating systems
 Utilizing software that requests an outdated operating system
 Run software formatted for other operating systems
 Test software on many different platforms
 Compile different servers for business use
 Safety and Security

Haresh Khachariya Department CS&IT | – Operating System (2020-21)

You might also like