Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

A

Laboratory File
On
Operating System

Submitted
For
Bachelor of Technology
In
Computer Science & Engineering
Batch : 2022-2026

At

Aravali College of Engineering & Management

Submitted To Submitted By
Mrs. Tanu Sharma Aditya Kumar Dubey
Assistant Professor CSE 2nd Year - A
CSE Roll No : 22011004003
OPERATING SYSTEMS LAB (PCC-CS-406)
INDEX

S. No. Documents Page No.


01 Dos’ & Don’ts
ii
02 Syllabus iii

03 List of Programs iv

05 H/W & S/W Requirements v

06 Program No -01. 1

07 Program No. -02 7

08 Program No. -03: 12

09 Program No. -04: 29

10 Program No. -05: 39

11 Program No. -06 41

12 Program No. -07 44

13 Program No. -08 47

Ms. Tanu Sharma Ms. Sakshi Kumar


Lab In-charge HOD (CSE)

i
GENERAL INSTRUCTIONS
DOs:

1. Switch off mobiles in the lab.

2. Bring your lab record with you.

3. Always come to the lab on time.

4. Maintain silence and be attentive.

5. Keep individual records of observations.

6. Always turn off the computer before leaving the lab.

7. Return all the materials issued to you before leaving the lab.
8. Read the instruction manual carefully before performing any experiment.

DON’Ts:

1. Change current setting.

2. Overcrowd near any equipment.

3. Drag the chair inside the lab.

4. Leave the lab till the class has concluded.

5. Take any material outside the lab with you.

6. Touch any machine / equipment/ model without supervision.

7. Use Eatables

ii
SYLLABUS
OPERATING SYSTEMS LAB (PCC-CS-406)

1. Study of WINDOWS 2000 Operating System.


2. Study of UNIX and LINUX Operating System.
3. To study the Execution of various basic commands, file/directory handling commands, word
count commands, Search Pattern Commands, Change Mode Commands.
4. Shell Programs
(i) Write a program to add, subtract, multiply and divide two numbers supplied as command
line arguments.
(ii) Write a program to calculate factorial of any number.
(iii) Write a program to generate Fibonacci series.
(iv) Write a shell script to reverse the digit and check whether the number entered is
palindrome or not.
(v) Write a program to find Prime Number
(vi) Write a Shell Script to find the number entered is even or odd
(vii) Write a Shell Script to find the sum of the digits of the number entered
(viii) Write a Shell Script to find the sum of the squares of first n natural numbers.
5. Write a C Program for implementing FCFS Scheduling.
6. Write a C Program for implementing SJF (Non-Preemptive) Scheduling.
7. Write a C Program for implementing SJF (Preemptive) Scheduling.
8. Write a C Program for implementing Priority (Non-Preemptive) Scheduling.
9. Write a C Program for implementing Priority (Preemptive) Scheduling.
10. Write a C Program for implementing Round Robin Scheduling.

iii
REQUIREMENT OF HARDWARE AND SOFTWARE

The Hardware and Software requirements for the lab are as follows:

HARDWARE REQUIREMENT:-

 A Computer System with at least 2 GB of RAM

SOFTWARE REQUIREMENT :-

 Linux Operating Systems


 Windows Operating Systems
 Turbo C

iv
OPERATING SYSTEMS LAB (PCC-CS-406)
LIST OF PROGRAMS

S.NO Program No. NAME OF THE EXPERIMENT


1. Program-1 Study of WINDOWS 2000 Operating System.

2. Program-2 Study of UNIX and LINUX Operating System.


3. Program-3 To study the Execution of various basic commands, file/directory
handling commands, word count commands, Search Pattern
Commands, Change Mode Commands.
4. Program-4 Shell Programs
(i) Write a program to add, subtract, multiply and divide two
numbers supplied as command line arguments.
(ii) Write a program to calculate factorial of any number.
(iii) Write a program to generate Fibonacci series.
(iv) Write a shell script to reverse the digit and check whether
the number entered is palindrome or not.
(v) Write a program to find Prime Number
(vi) Write a Shell Script to find the number entered is even or
odd
(vii) Write a Shell Script to find the sum of the digits of the
number entered
(viii) Write a Shell Script to find the sum of the squares of first
n natural numbers.
5. Program-5 Write a C Program for implementing FCFS Scheduling.
6. Program-6 Write a C Program for implementing SJF (Non-Preemptive)
Scheduling.
7. Program-7 Write a C Program for implementing Priority (Non-Preemptive)
Scheduling.
8. Program-8 Write a C Program for implementing Round Robin Scheduling.

v
Roll No. : 22011004003

Program 1

Objective:

Study of WINDOWS 2000 Operating System

Theory:
1. Introduction to Windows 2000

Windows 2000 (also referred to as Win2K) is a preemptive, interruptible, graphical and business-
oriented operating system designed to work with either uniprocessor or symmetric multi-processor
computers. It is part of the Microsoft Windows NT line of operating systems and was released on
17 February 2000. It was succeeded by Windows XP in October 2001 and Windows Server 2003
in April 2003. It is a hybrid kernel operating system.

2. Architecture of The Windows 2000 operating system

The Windows 2000 operating system architecture consists of two layers (user mode and kernel
mode) , with many different modules within both.

2.1. User mode

User mode in Windows 2000 is made of subsystems capable of passing I/O requests to the
appropriate kernel mode drivers by using the I/O manager. Two subsystems make up the user
mode layer of Windows 2000: the environment subsystem and the integral subsystem. The
environment subsystem is designed to run applications written for many different types of

1
Roll No. : 22011004003

operating systems. These applications, however, run at a lower priority than kernel mode
processes. There are three main environment subsystems:

1. A Win32 subsystem runs 32-bit Windows applications and also supports Virtual DOS
Machines (VDMs) , which allow MS-DOS and 16-bit Windows 3.1x (Win16) applications
to run on Windows.
2. An OS/2 environment subsystem supports 16-bit character-based OS/2 applications and
emulates OS/2 1.3 and 1.x, but not 32-bit or graphical OS/2 applications as used on OS/2
2.x or later.
3. A POSIX environment subsystem supports applications that are strictly written to either the
POSIX.1 standard or the related ISO/IEC standards.

The integral subsystem looks after operating system specific functions on behalf of the
environment subsystem. It consists of a security subsystem (which grants/denies access and
handles logons) , workstation service (which helps the computer gain network access) and a server
service (which lets the computer provide network services).

2.2 Kernel mode

Kernel mode in Windows 2000 has full access to the hardware and system resources of the
computer. The kernel mode stops user mode services and applications from accessing critical areas
of the operating system.

Each object in Windows 2000 exists in its own namespace, as illustrated by this screenshot from
SysInternal's WinObj

3. Common features of the Windows 2000 operating system

3.1 Windows Explorer

3.2 NTFS

3.3 Encrypting File System

The Encrypting File System (EFS) introduced strong file system-level encryption to Windows. It
allows any folder or drive on an NTFS volume to be encrypted transparently by the user EFS works
together with the EFS service, Microsoft's CryptoAPI and the EFS File System Runtime Library
(FSRTL). To date, its encryption has not been compromised.

3.4 Basic and dynamic disk storage

Windows 2000 introduced the Logical Disk Manager for dynamic storage. All versions of
Windows 2000 support three types of dynamic disk volumes (along with basic disks) : simple
volumes, spanned volumes and striped volumes:

 Simple volume, a volume with disk space from one disk.

2
Roll No. : 22011004003

 Spanned volumes, where up to 32 disks show up as one, increasing it in size but not
enhancing performance. When one disk fails, the array is destroyed. Some data may be
recoverable. This corresponds to JBOD and not to RAID-1.
 Striped volumes, also known as RAID-0, store all their data across several disks in stripes.
This allows better performance because disk reads and writes are balanced across multiple
disks.

3.5 Accessibility

Microsoft increased the usability of Windows 2000 over Windows NT 4.0 for people with visual
and auditory impairments and other disabilities. They included several utilities designed to make
the system more accessible, although many of these features were already available with previous
versions of Windows:

 FilterKeys: a group of keyboard-related features for people with typing issues, including:
o SlowKeys: Ignore any keystroke not held down for a certain period.
o BounceKeys: Ignore repeated keystrokes pressed in quick succession.
o RepeatKeys: lets users slow down the rate at which keys are repeated via the
keyboard's key-repeat feature.
 ToggleKeys: when turned on, Windows will play a sound when the CAPS LOCK, NUM
LOCK or SCROLL LOCK key is pressed.
 MouseKeys: lets users move the cursor around the screen via the numeric keypad.
 On-screen keyboard: displays a virtual keyboard on the screen and allows users to press
its keys using a mouse or a joystick.
 SerialKeys: lets Windows 2000 support speech augmentation devices.
 StickyKeys: makes modifier keys (ALT, CTRL and SHIFT) become "sticky": a user can
press the modifier key, and then release it before pressing the combination key. (Activated
by pressing Shift five times quickly.)
 Microsoft Magnifier: A screen magnifier that enlarges a part of the screen the cursor is
over.
 Microsoft Narrator: Introduced in Windows 2000, this is a screen reader that utilizes the
Speech API
 High contrast theme: to assist users with visual impairments.
 SoundSentry: designed to help users with auditory impairments, Windows 2000 shows a
visual effect when a sound is played through the sound system.

3..6 Languages and locales

Windows 2000 introduced the Multilingual User Interface (MUI). Besides English, Windows 2000
incorporates support for Arabic, Armenian, Baltic, Central European, Cyrillic, Georgian, Greek,
Hebrew, Indic, Japanese, Korean, Simplified Chinese, Thai, Traditional Chinese, Turkic,
Vietnamese and Western European languages.[10] It also has support for many different locales.

3
Roll No. : 22011004003

3.7 Games

Windows 2000 included version 7.0 of the DirectX API, commonly used by game developers on
Windows 98. The last version of DirectX that Windows 2000 supports is DirectX 9.0c (Shader
Model 3.0), that shipped with Windows XP Service Pack 2. Currently, Microsoft publishes
quarterly updates to DirectX 9.0c; these updates contain bug fixes to the core runtime and some
additional libraries such as D3DX, XAudio 2, XInput and Managed DirectX components. The
majority of games written for recent versions of DirectX can therefore run on Windows 2000.

3.8 System utilities


 The Windows 2000 Computer Management console can perform many system tasks. It is
pictured here starting a disk defragmentation.
 Windows 2000 introduced the Microsoft Management Console (MMC), which is used to
create, save, and open administrative tools.
 The main tools that come with Windows 2000 can be found in the Computer Management
console (in Administrative Tools in the Control Panel This contains the Event Viewer—a
means of seeing events and the Windows equivalent of a log file, a system information
utility, a backup utility,
 Task Scheduler and management consoles to view open shared folders and shared folder
sessions, configure and manage COM+ applications, configure Group Policy, manage all
the local users and user groups, and a device manager
 Windows 2000 comes with two utilities to edit the Windows registry, REGEDIT.EXE and
REGEDT32.EXE. REGEDIT has been directly ported from Windows 98,
 The System File Checker (SFC) also comes with Windows 2000. It is a command line
utility that scans system files and verifies whether they were signed by Microsoft and works
in conjunction with the Windows File Protection mechanism. It can also repopulate and
repair all the files in the Dllcache folder.

3.9 Recovery Console


The Recovery Console is usually used to recover unbootable systems.The Recovery Console is
run from outside the installed copy of Windows to perform maintenance tasks that can neither be
run from within it nor feasibly be run from another computer or copy of Windows 2000. It is
usually used to recover the system from problems that cause booting to fail, which would render
other tools useless.It has a simple command line interface, used to check and repair the hard
drive(s) , repair boot information (including NTLDR) , replace corrupted system files with fresh
copies from the CD, or enable/disable services and drivers for the next boot.

4. Server family features

The Windows 2000 server family consists of Windows 2000 Server, Windows 2000 Advanced
Server, and Windows 2000 Datacenter Server.All editions of Windows 2000 Server have the
following services and features built in:

 Routing and Remote Access Service (RRAS) support, facilitating dial-up and VPN
connections, support for RADIUS authentication, network connection sharing, Network
Address Translation, unicast and multicast routing schemes. 

4
Roll No. : 22011004003

 DNS server, including support for Dynamic DNS. Active Directory relies heavily on DNS.
 IPsec support and TCP/IP filtering
 Smart card support
 Microsoft Connection Manager Administration Kit (CMAK) and Connection Point
Services
 Support for distributed file systems (DFS)
 Hierarchical Storage Management support including remote storage, a service that runs
with NTFS and automatically transfers files that are not used for some time to less
expensive storage media
 Fault tolerant volumes, namely Mirrored and RAID-5
 Group Policy (part of Active Directory)
 IntelliMirror, a collection of technologies for fine-grained management of Windows 2000
Professional clients that duplicates users' data, applications, files, and settings in a
centralized location on the network. IntelliMirror employs technologies such as Group
Policy, Windows Installer, Roaming profiles, Folder Redirection, Offline Files (also known
as Client Side Caching or CSC), File Replication Service (FRS), Remote Installation
Services (RIS) to address desktop management scenarios such as user data management,
user settings management, software installation and maintenance.
 COM+ and MTS
 MSMQ 2.0
 TAPI 3.0
 Security Support Provider Interface (SSPI)
 Integrated Windows Authentication (including Kerberos and SPNEGO authentication).
 MS-CHAP v2 protocol
 Public Key Infrastructure (PKI) and Enterprise Certificate Authority support
 Terminal Services and support for the Remote Desktop Protocol (RDP) 
 Internet Information Services (IIS) 5.0 and Windows Media Services 4.1

The Server editions include more features and components, including the Microsoft Distributed
File System (DFS) , Active Directory support and fault-tolerant storage.

4.1 Distributed File System

The Distributed File System (DFS) allows shares in multiple different locations to be logically
grouped under one folder, or DFS root.

4.2 Active Directory

A new way of organizing Windows network domains, or groups of resources, called Active
Directory, is introduced with Windows 2000 to replace Windows NT's earlier domain model.
Active Directory's hierarchical nature allowed administrators a built-in way to manage user and
computer policies and user accounts, and to automatically deploy programs and updates with a
greater degree of scalability and centralization than provided in previous Windows versions.
Active Directory requires a DNS server that supports SRV resource records, or that an
organization's existing DNS infrastructure be upgraded to support this. There must be one or

5
Roll No. : 22011004003

more domain controllers to hold the Active Directory database and provide Active Directory
directory services.

4.3 Volume fault tolerance

Along with support for simple, spanned and striped volumes, the server family of Windows 2000
also supports fault-tolerant volume types. The types supported are mirrored volumes and RAID-5
volumes:

 Mirrored volumes: the volume contains several disks, and when data is written to one it
is also written to the other disks. This means that if one disk fails, the data can be totally
recovered from the other disk. Mirrored volumes are also known as RAID-1.
 RAID-5 volumes: a RAID-5 volume consists of multiple disks, and it uses block-level
striping with parity data distributed across all member disks. Should a disk fail in the array,
the parity blocks from the surviving disks are combined mathematically with the data
blocks from the surviving disks to reconstruct the data on the failed drive "on-the- fly".

Viva Voice:
1. What is an Operating System?
2. What are the features of Windows OS?
3. What do you mean by File System? What are its types? Which file system is used in
Windows OS?
4. Explain the architectural modes of Windows OS.
5. What do you mean by Active Directory?
6. What is Distributed File Systems?
7. What is Process structure for Windows OS?
8. Which scheduling is followed in Windows OS?
9. What is the difference between FAT and NTFS?
10. What is a Server family OS?

6
Roll No. : 22011004003

Program 2

Objective:

Study of UNIX and LINUX Operating System

Theory:
UNIX Operating System
The Unix operating system is a set of programs that act as a link between the computer and the
user.
The computer program that allocates the system resources and coordinates all the details of the
computer's internal is called the operating system or the kernel.

Users communicate with the kernel through a program known as the shell. The shell is a command
line interpreter; it translates commands entered by the user and converts them into a language that
is understood by the kernel.

 UNIX was originally developed in 1969 by a group of AT&T employees Ken Thompson, Dennis
Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs. 

 There are various UNIX variants available in the market. Solaris UNIX, AIX, HP UNIX and BSD
are a few examples. Linux is also a flavor of UNIX which is freely available. 

 Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser
system.
 A user can also run multiple programs at the same time; hence UNIX is a multitasking
environment.

UNIXArchitecture
The main concept that unites all the versions of UNIX is the following four basics –

 Kernel− The kernel is the heart of the operating system. It interacts with the hardware and most
of the tasks like memory management, task scheduling and file management.
 Shell− The shell is the utility that processes your requests. When you type in a command at your
terminal, the shell interprets the command and calls the program that you want. The shell uses
standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous
shells which are available with most of the UNIX variants.

7
Roll No. : 22011004003

 Commands and Utilities− There are various commands and utilities which you can make use of
in your day to day activities cp, mv, cat and grep, etc. are few examples of commands and utilities.
There are over 250 standard commands plus numerous others provided through 3 rdparty software.
All the commands come along with various options.
 Files and Directories− All the data of UNIX is organized into files. All files are then organized
into directories. These directories are further organized into a tree-like structure called the
Filesystem.

LINUX Operating System


Linux is one of popular version of UNIX operating System. It is open source as its source code is
freely available. It is free to use. Linux was designed considering UNIX compatibility. Its
functionality list is quite similar to that of UNIX.

ComponentsofLinuxSystem
Linux Operating System has primarily three components

 Kernel− Kernel is the core part of Linux. It is responsible for all major activities of this operating
system. It consists of various modules and it interacts directly with the underlying hardware.
Kernel provides the required abstraction to hide low level hardware details to system or application
programs.

8
Roll No. : 22011004003

 System Library− System libraries are special functions or programs using which application
programs or system utilities accesses Kernel's features. These libraries implement most of the
functionalities of the operating system and do not requires kernel module's code access rights.

 System Utility− System Utility programs are responsible to do specialized, individual level tasks. 

BasicFeatures
Following are some of the important features of Linux Operating System.

 Portable− Portability means software can works on different types of hardware in same way.
Linux kernel and application programs support their installation on any kind of hardware platform. 

 Open Source− Linux source code is freely available and it is community based development
project. Multiple teams work in collaboration to enhance the capability of Linux operating system
and it is continuously evolving. 

 Multi-User− Linux is a multiuser system means multiple users can access system resources like
memory/ ram/ application programs at same time. 

 Multiprogramming− Linux is a multiprogramming system means multiple applications can run


at same time. 

9
Roll No. : 22011004003

 Hierarchical File System− Linux provides a standard file structure in which system files/ user
files are arranged.

 Shell − Linux provides a special interpreter program which can be used to execute commands of
the operating system. It can be used to do various types of operations, call application programs.
etc.

 Security − Linux provides user security using authentication features like password protection/
controlled access to specific files/ encryption of data.

Architecture
The following illustration shows the architecture of a Linux system −

The architecture of a Linux System consists of the following layers −

 Hardware layer− Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).

 Kernel− It is the core component of Operating System, interacts directly with hardware, provides
low level services to upper layer components.

 Shell− An interface to kernel, hiding complexity of kernel's functions from users. The shell takes
commands from the user and executes kernel's functions. 

10
Roll No. : 22011004003

 Utilities− Utility programs that provide the user most of the functionalities of an operating
systems. 

Viva Voice:
1. How Windows OS is different from Unix / Linux OS? What are the features that
make Unix / Linux to be superior than Windows?
2. What do you mean by Kernel? What is its purpose? Does Windows OS have a
Kernel?
3. What are the different layers in Linux OS?
4. What is Shell? How can it be implemented in Unix / Linux?
5. What kinds of shells can be there?
6. What do you mean by an Open Source?
7. What do you mean by a Utility?
8. What are the basic components of Linux?
9. What is the importance of the GNU project?
10. Describe the root account.

11
Roll No. : 22011004003

Program 3

Objective:
To study the Execution of various Basic Commands, File/Directory Handling Commands,
Word Count Commands, Search Pattern Commands, File Access Permission Commands.

Theory:

Basic Linux Commands:

 type: It is a general purpose command which is used to start other command line.

 who: It shows who is logged onto the linux system.

 who am i: It tells through user the person is logged in.

 uname: It is used to print the name of the OS.


 uname -r: It tells the version of the Linux OS.
 uname -n: It tells the name of the system the user is using.

 cal: It displays the calender of the running system.

 date: It displays the current date and the time of the system.

12
Roll No. : 22011004003

 man: Linux man command stands for ''manual''. It shows description and all the options
available which can be used with the command.

Example : man cal

 banner: It is used to take input string from user and display it in a highlighted manner.

13
Roll No. : 22011004003

 echo: It is used to display the input given by the user.

File Processing Commands


There are basically three type of files in Linux environment.
1.Directory files
2.Device files
3.Ordinary files

1. Directory Files:

Linux stores data and programs in files. These are organized in directories. In a simple way, a
directory is just a file that contains other files (or directories).

The part of the hard disk where you are authorised to save data is calle your home directory.
Normally all the data you want will be saved in files and directories in your home directory. To
find your home directory (if you need), type:

echo $HOME

2. Device Files:

Linux, like all versions of Unix presents its hardware devices as special files. So, for example,
/dev/null is the null device. A device file does not use any data space in the file system, it is only
an access point to the device driver. The EXT2 file system and the Linux VFS both implement
device files as special types of inode. There are two types of device file; character and block special
files. Within the kernel itself, the device drivers implement file semantices: you can open them,
close them and so on. Character devices allow I/O operations in character mode and block devices
require that all I/O is via the buffer cache. When an I/O request is made to a device file, it is
forwarded to the appropriate device driver within the system.

14
For example, the IDE disks on the first IDE controller in the system have a major number of 3 and
the first partition of an IDE disk would have a minor number of 1. So, ls -l of /dev/hda1 gives:

$ brw-rw---- 1 root disk 3, 1 Nov 24 15:09 /dev/hda1

3. Ordinary files:
A large majority of the files found on UNIX and Linux systems are ordinary files. Ordinary files
contain ASCII (human-readable) text, executable program binaries, program data, and more.

Device or special files are used for device I/O on UNIX and Linux systems. They appear in a file
system just like an ordinary file or a directory.

On UNIX systems there are two flavors of special files for each device, character special files
and block special files. Linux systems only provide one special file for each device.

Commands in File Processing:

 ls command
The ls command stands for the list command and function in the linux terminal to show all of
the major directories. File under a given file system.
For example:- ls/application will show the user all of he folders stored in the application file.

The ls command show the file and directories in your current directory

Note: Directories are denoted in blue color and file were denoted in white color.

15
Roll No : 22011004003

The ls command can be used with various option few of them are :-
 ls_R:- it shows all the files not only in the directories but also in the sub directories.

 ls-a:- Hidden items in UNIX and Linux begins with a .(dot) period symbol. To view the
hidden files we can use the command ls-a.

 ls-al :- It gives the detailed information of the file in a columnar format. The column
contains the following information.

16
Roll No : 22011004003

File type & No. of Owner & Group of the File size in Date & time Directory &
access hard creator of file owner byte file name
permissions links to
the file

 mkdir : It is an acronym for 'make directory‖. The directories or sub directories in linux can be
created by this command. The syntax is as follows-
mkdir <directory name>
This command will create a sub directory in your presnt working directory which is
usually ―HOME directory‖.
If you want to create a directory in a different location other than HOME directory then
you need to specify the whole path in the command. For example, we want to make a sub directory
named ―MUSIC‖ in the temporary directory then we need to specify the command as follows-
mkdir /temp/MUSIC
If we want to create multiple directories in none directory then we can use the command as follows
-
mkdir dir1 dir2 dir3

17
Roll No : 22011004003

 cd — Use the "cd" command to go to a directory. For example, if you are in the home
folder, and you want to go to the downloads folder, then you can type in “cd Downloads”.

18
Roll NO. : 22011004003

Remember, this command is case sensitive, and you have to type in the name of the folder
exactly as it is. But there is a problem with these commands. Imagine you have a folder named
―Raspberry Pi‖. In this case, when you type in “cd Raspberry Pi”, the shell will take the
second argument of the command as a different one, so you will get an error saying that the
directory does not exist. Here, you can use a backward slash. That is, you can use “cd
Raspberry\ Pi” in this case. Spaces are denoted like this: If you just type “cd” and press enter,
it takes you to the home directory. To go back from a folder to the folder before that, you can
type ―cd ..‖ . The two dots represent back.

 rmdir : It is an acronym for ―Remove Directory‖. In case we want to remove any directory
then this command can be used. Before using this command we should ensure that there is no file
or sub directory under the directory you want to delete. Delete the files of directory of subdirectory
first, before deleting the parent directory.

19
Roll No. : 22011004003

 Renaming directories: the mv command can be used for renaming the directories. The
syntax is as follows-
mv <old dir name> <new dir name>

Creating and Viewing Files:

 touch: The touch command is used to create a file. It can be anything, from an empty txt file
to an empty zip file. For example, ―touch new.txt‖.

 cat command : The cat command is user to display text files. It can also be used for copying,
combining and creating new text files.
To create a new file –
1. cat > filename.txt
2. Add the content.
3. Press Ctrl+D to return to the
terminal.

20
To view the files use the cat
command as-
$ cat filename.txt
To combine two text files-
$ cat filename1.txt filename2.txt > filename

 mv: To move and rename files-


To move a file use the mvcommand. The syntax is as follows:
$ mv filename.txt <new file location>

To rename a file use the mv command with the following syntax:


$ mv filename1.txt filename2.txt

21
 rm: To delete files- To delete a file from the system rm command is used. The syntax is as
follows
$ rm filename

 cp — Use the cp command to copy files through the command line. It takes two arguments:
The first is the location of the file to be copied, the second is where to copy.

4. History:-The history command shows all the commands that you have used in the past for
the current terminal session.

22
Roll No 22011004003

Commands for counting words, lines and characters:


 wc: The wc command is used for counting the number of words in a file. The syntax is
as follows:
wc filename
it can be used with various following options:
1) wc -l: This option can be used for counting the number of lines in the files.
2) wc -c: This option can be used for counting the characters in a file.
3) wc -w: This option can be used for counting the number of words in a file.

 cmp
cmp command in linux or unix is used to compare the two files byte by byte and helps you to
find out whether the two files are identical or not.
● When cmp is used for comparison between two files it reports the location of the first
mismatch to the screen if difference is found and if no difference is found, the files are
compared to be identical.
● Cmp displays no message and simply return the prompt if the files compared
atre identical. The syntax is as follows:
$ cmp file1.txt file2.txt
● this command can be used in various options
1) cmp -b: By this option cmp displays the different bytes in the output.
2) cmp -i: This option when used with cmp command. It helps to skip a particular number
of initial bytes from both the files and then after skipping it compares the files. This can
be done by specifying the number of bytes as line arguments to the -i option. The syntax
for this will be:
$ cmp -i 10 file1.txt file2.txt
23
3) cmp -i(bytes to be skipped from file 1):)bytes to be skipped from file2)
$ cmp -i 5:12 sau.txt sac.txt
4) cmp -in(number of files to be compared): This option allows you the limit in the number
of bytes to be compared. Ex: to compare only 50 bytes when the following command is
used.
$ cmp -n 50 file1.txt file2.txt

 Join: Join command works on the first field of the two files.

24
● join works on the sorted list. If the input file is not sorted it will display a warning
or error message. For ex:

If we don't want to use the sorted manner we can use the following command:
$ join –nocheck-order test3.txt test2.txt

25
 Search Pattern Command – grep Command:

The grep filter searches a file for a particular pattern of characters and displays all the lines that
contain that pattern. The pattern that is searched in the file is referred to as the regular expression.
The syntax for the command is as follows:
$ grep [option] pattern [files]
This command can be used with various options:
1. -i : This ignores the base of matching.

2. -c : This prints only a count of the lines that match a pattern.


3. -h : This displays the matched lines but does not displays the file names.
4. -l : It displays the list of file names only.
5. -n : It displays the matched lines and their line numbers.
6. -v : This prints out all the lines that do not match the pattern.
7. -w : It matches the whole word.
8. -o : It prints only the matched parts of a matching line with each such part on a seperate
output line.

26
 Change Mode Command - chmod Command:
On linux and unix like Operating System, there is a set of rules for each file which defines who
can access that file and how they can access it. These rules are called file permissions or file
modes. The command name $ chmod stands for change mode and it is used to define the way a
file can be accessed. The permissions are defined for the owner of the file, members of the group
who own the file and anyone else. There are two ways to represent these permissions:
1. With alphanumeric characters
2. with octal numbers from 0 to 7
The permissions defined by octal numbers can be as follows:
● 4 stands for ―read‖.
● 2 stands for ―write‖.
● 1 stands for ―execute‖.
● 0 stands for ―no permission‖.
● 3 stands for ―write and execute‖.
● 5 stands for ―read and execute‖.
● 6 stands for ―read and write‖.
● 7 stands for ―read, write and execute‖.
The syntax of the command is:
chmod option permission filename.txt
Example: $ chmod 754 cse5bg2.txt

27
 sudo-apt-get

sudo — A widely used command in the Linux command line, sudo stands for "SuperUser Do".
So, if you want any command to be done with administrative or root privileges, you can use
the sudo command. For example, if you want to edit a file like viz. alsa-base.conf, which needs
root permissions, you can use the command – sudo nano alsa-base.conf. You can enter the root
command line using the command ―sudo bash‖, then type in your user password. You can also
use the command ―su‖ to do this, but you need to set a root password before that. For that, you
can use the command ―sudo passwd‖(not misspelled, it is passwd). Then type in the new root
password.

apt-get — Use apt to work with packages in the Linux command line. Use apt-get to install
packages. This requires root privileges, so use the sudocommand with it. For example, if you want
to install the text editor jed (as I mentioned earlier), we can type in the command ―sudo apt-
get install jed‖. Similarly, any packages can be installed like this. It is good to update your
repository each time you try to install a new package. You can do that by typing ―sudo apt-get
update‖. You can upgrade the system by typing ―sudo apt-get upgrade‖. We can also upgrade
the distro by typing ―sudo apt-get dist-upgrade‖. The command ―apt-cache search‖ is used to
search for a package. If you want to search for one, you can type in ―apt-cache search jed‖(this
doesn't require root).

28
Viva Voice:

1. Which command is used to count the words from a text file?


2. Which command is used to display the top of the file?
3. Which command is used to remove a directory?
4. Which of the following commands is used to display the directory attributes rather than
its contents?
5. Which command is used to identify all the files beginning with the string 'emp' and
followed by a non-numeric character?
6. Which command is used to delete all files in the current directory and all its sub-
directories?
7. Which command is used to set the access permissions on files?
8. Which command is used to create a text file?
9. What is a directory?
10. When you create a file using command line, where it is formed?

29
Program 4 - Shell Programs
Program (i)

Objective:

Write a program to add, subtract, multiply and divide two numbers supplied as command
line arguments.

Code:

#!/bin/bash
clear
echo "Enter No. 1"
read a
echo "Enter No. 2"
read b
c=`expr $a + $b`
echo "the addition of $a and $b is $c"

clear
echo "Enter No. 1"
read a
echo "Enter No. 2"
read b
c=`expr $a - $b`
echo "the subtraction of $a and $b is $c"

clear
echo "Enter No. 1"
read a
echo "Enter No. 2"
read b
c=`expr $a \* $b`
echo "the multiplication of $a and $b is $c"

clear
echo "Enter No. 1"
read a
echo "Enter No. 2"
read b
c=`expr $a / $b`
echo "the division of $a and $b is $c"

30
31
Program (ii)

Objective:

Write a program to calculate factorial of any number.

Code:

#!/bin/bash
clear
echo "ENTER A NUMBER-"
read n
fct=1
i=1
while test $i -le $n
do
fct=`expr $fct \* $i`
i=`expr $i + 1`
done
echo "THE FACTORIAL OF THE NUMBER IS -" $fct

32
Program (iii)

Objective:
Write a program to generate Fibonacci series.

Code:

#!/bin/bash
clear
echo enter the range of the fibonacci series----
read n
echo "the series is as follows:"
echo
a=0
b=1

i=2
echo $a
echo $b
while test $i -lt $n
do

c=`expr $a + $b`
echo $c
a=$b
b=$c
i=`expr $i + 1`
done

33
34
Program (iv)

Objective:

Write a shell script to reverse the digit and check whether the number entered is
palindrome or not.

Code:

#!/bin/bash
Clear
echo "ENTER A NUMBER-"
read n
rev=0
t=$n
while test $n -ne 0
do
r=`expr $n % 10`
rev=`expr $rev \* 10`
rev=`expr $rev + $r`
n=`expr $n / 10`
done
echo "THE REVERSE IS-$rev"
if test $rev -eq $t
then
echo "THE NUMBER IS PALINDROME"
else
echo "THE NUMBER IS NOT PALINDROME"
fi

35
36
Program (v)

Objective:
Write a program to find Prime Number.
Code:
#!/bin/bash
clear
echo "Enter a number: \c"
read num

i=2
rem=1

if [ $num -lt $i ];
then
echo "$num is not a prime number.\n"
exit 0
fi

while [ $i -le `expr $num / 2` -a $rem -ne 0 ];


do
rem=`expr $num % $i`
i=`expr $i + 1`
done

if [ $rem -ne 0 ];
then
echo "$num is a prime number.\n"
else
echo "$num is not a prime number.\n"
fi

37
38
Program (vi)

Objective:
Write a Shell Script to find the number entered is even or odd
Code:

#!/bin/bash
clear
echo “Enter a number:”€•
read n
rem=$(($n % 2))
if [ $rem -eq 0 ]
then
echo œ”Even number”
else
echo œ”Odd number”€•
fi

39
Program (vii)

Objective:
Write a Shell Script to find the sum of the digits of the number entered
Code:

#!/bin/bash
clear
echo "ENTER A NUMBER-"
read n
sum=0
while test $n -ne 0
do
dig=`expr $n % 10`
sum=`expr $sum + $dig`
n=`expr $n / 10`
done
echo "THE SUM OF DIGITS OF $n IS- $sum"

40
Program (viii)

Objective:
Write a Shell Script to find the sum of the squares of first n natural numbers.
Code:

#!/bin/bash
clear
echo ENTER THE NUMBER OF ELEMENTS-
read n
i=1
sum=0
while test $i -le $n
do
p=`expr $i \* $i`
sum=`expr $sum + $p`
i=`expr $i + 1`
done
echo $sum

41
Viva Voice:
1. What is Shell Scripting? How scripts are being made in Linux?
2. How many types of Shells are there?
3. What are the two different modes in vi editor?
4. What is the command used to append text after current line?
5. How to enter from command mode to insertion mode?
6. What is the difference between zz and :wq commands?
7. How do you terminate a shell script if statement?
8. What code would you use in a shell script to determine if a directory exists?
9. How do you read keyboard input in shell scripts?
10. How do you find out what’s your shell?
11. Write the syntax for switch case in shell script.

42
Program 5

Objective:

Write a C Program for implementing FCFS Scheduling.

Code:
#include<stdio.h>

int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);

printf("\nEnter Process Burst Time\n");


for(i=0;i<n;i++)
{
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
}

wt[0]=0; //waiting time for first process is 0

//calculating waiting time


for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}

printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");

//calculating turnaround time


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}

avwt/=i;
avtat/=i;
43
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);

return 0;
}

OUTPUT:

Viva Voice:

1. What is CPU scheduling? What are the criteria for CPU Scheduling?
2. What is the Turnaround time, Burst Time, Waiting Time and Arrival Time?
3. Suppose that the following processes arrive for execution at the time indicated:
Arrival Burst Time
Process
Time (s) (s)
P0 0 2
P1 1 5
P2 2 7
P3 1 4
P4 3 3

Calculate the Average Turnaround Time and Average Waiting Time for FCFS
Scheduling Algorithm.
4. What are Schedulers? Explain its types.

44
Program 6

Objective:

Write a C Program for implementing SJF Scheduling (Non-Preemptive)

Code:

#include<stdio.h>

void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);

printf("\nEnter Burst Time:\n");


for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}

//sorting burst time in ascending order using selection sort


for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for first process will be zero

45
//calculate waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}

avg_wt=(float)total/n; //average waiting time


total=0;

printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=(float)total/n; //average turnaround time


printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}

OUTPUT:

46
Viva Voice:

1. Suppose that the following processes arrive for execution at the time indicated:

Arrival Burst
Process Priority
Time (s) Time (s)
P0 0 5 1
P1 0 3 3
P2 1 8 2
P3 2 6 1
P4 3 7 4

Calculate the Average Turnaround Time and Average Waiting Time for the following:

 SJF Non-Preemptive
 SJF Preemptive

47
Program 7

Objective:
Write a C Program for implementing Priority Scheduling (Non-Preemptive)

Code:

#include<stdio.h>

int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);

printf("\nEnter Burst Time and Priority\n");


for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1; //contains process number
}

//sorting burst time, priority and process number in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];

48
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for first process is zero

//calculate waiting time


for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}

avg_wt=total/n; //average waiting time


total=0;

printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=total/n; //average turnaround time


printf("\n\nAverage Waiting Time=%d",avg_wt);
printf("\nAverage Turnaround Time=%d\n",avg_tat);

return 0;
}

49
OUTPUT:

Viva Voice:
1. Suppose that the following processes arrive for execution at the time indicated:

Arrival Burst
Process Priority
Time (s) Time (s)
P0 0 5 1
P1 0 6 3
P2 1 9 2
P3 2 8 1
P4 1 10 4

Calculate the Average Turnaround Time and Average Waiting Time for the following:

 Priority Non-Preemptive
 Priority Preemptive

50
Program 8

Objective:

Write a C Program for implementing Round Robin Scheduling.

Code:
#include<stdio.h>

int main()
{

int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);

51
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}

OUTPUT:

52
Viva Voice:

1. What is the algorithm of Round Robin Scheduling? How it works?


2. Suppose that the following processes arrive for execution at the time indicated:

Arrival Burst Time


Process
Time (s) (s)
P0 0 2
P1 1 5
P2 2 7
P3 1 4
P4 3 3

Calculate the Average Turnaround Time and Average Waiting Time for Round
Robin Scheduling?

53

You might also like