OS Lab Manual
OS Lab Manual
Lab Manual
Subject: Operating System Lab
Subject Code: BTIT-405-18
2
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
INDEX
Sr.no Content Page No
I Course Objectives and Outcomes 4
II List of Experiments 5
Installation Process of various operating systems.
1 a. Installation of Microsoft Windows Operating System 6 - 18
b. Installation of Ubuntu Linux Operating System
Implementation of CPU scheduling algorithms to find turnaround
time and waiting time.
a. First Come First Serve (FCFS)
2. 19-27
b. Shortest Job First (SJF)
c. Round Robin
d. Priority
Virtualization, Installation of Virtual Machine Software and
installation of Operating System on Virtual Machine.
3 a. Introduction to Virtualization and Installation of virtual box 28-39
b. Steps to create virtual machine using virtual box
c. Installation of Linux operating systems using virtual box.
Commands for files & directories:
a. cd, ls, cp, md, rm, mkdir, rmdir. Creating and viewing files
4 using cat. 40-49
b. File comparisons, batch commands, kill, ps, who, sleep.
Grep, Cal, Sort,Date commands.
Shell Programming: Basic of shell programming, various types of
shell.
a. Basic of shell programming
5 50-55
b. To study arithmetic expression , conditional statement ,loops
in shell program.
c. Creating shell programs for automating system tasks.
6 Implementation of Bankers algorithm for the purpose of deadlock 56-58
avoidance.
Content Beyond Syllabus
7 Implementation of Reader Writer problem using Semaphores 59-61
8 Implementation of FCFS Disk Scheduling Algorithm 62
9 Implementation of SSTF Disk Scheduling Algorithm 63
Prepared by Approved by
3
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Course Outcomes
C216.1 Interpret and implement basic services and functionalities of the operating system
Analyze and simulate CPU Scheduling Algorithms like FCFS, Round Robin, SJF, and
C216.2
Priority
C216.3 Implement commands for files and directories
4
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
List of Experiments
Sr.no List of Experiments Relevance to CO
PREPARED BY APPROVED BY
5
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
IKGPTU, Jalandhar
Syllabus
6
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Experiment No:-1(a)
2. Now get an USB flash drive or optical CD Drive and create a bootable device drive from
PowerISO/Rufus. Here I’m using a USB flash Drive.
6
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
3. Once Completed reboot your PC and press ESC/DEL/F10 to enter into the BIOS. Check the key
online according to your PC brand. In BIOS edit boot sequence program and set your bootable
device on top. Now Save and Exit BIOS. If done correctly your PC will start booting from your
bootable device.
4. Once booted successfully you’ll see the first window of installation. Now here Choose your
Language, Time and currency format, Keyboard layout or let it be the Default i.e. English (US)
and hit Next.
7
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
5. Now you will see a Install Now button hit it to start the setup.
6. Once you hit Install Now the setup will start gathering hardware information and it will
automatically take you to the next level.
8
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
7. Now on next window it will ask you for your CD key. Enter the CD key you have bought from
the Microsoft. You can use the on-screen keyboard or normal keyboard.
8. Now accept the Terms and Conditions from Microsoft and hit Next.
9
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
9. Now choose an option suitable for you. You can upgrade a previously installed window or custom
install from the scratch. Here I’m selecting Custom installation.
10. Now after you select Custom installation you will land on a window called as Partitioning
window. Here you can create different Local Disk partitions of your HDD drive or you can
select the partition containing the previous window.
11. Once you are done with your partitioning hit Next and your window will start installing. After
it finishes up the window will ask for reboot. Reboot the window and remove your bootable
device before window boot again.
10
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
12. Once the window boot again you will see the this personalize section where you can change
the background colour of your window choose your favourite colour and hit Next.
13. Now after Personalizing, select the type of setting you want to set for your window. Here I’m
using Express settings. You can also use custom to change some settings. These setting contains
Automatic Update installation, Data sharing with Microsoft etc.
11
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
14. After your settings you will be asked to Name your PC and User and set a password. You can set
password as None if you want and hit Done. This will be your last step after that your window
will be shown as bellow.
12
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Introduction: Ubuntu is an operating system with Linux kernel based on Debian and distributed as free
and open source software. It’s one of the most popular operating systems for Desktop and Server.
1. Using a DVD?
It’s easy to install Ubuntu from a DVD. Here’s what you need to do:
Restart your computer. You should see a welcome screen prompting you to choose your language and
giving you the option to install Ubuntu or try it from the DVD.
If you don’t get this menu, read the booting from the DVD guide for more information.
Step 1: Most new computers can boot from USB. You should see a welcome screen prompting you to
choose your language and giving you the option to install Ubuntu or try it from the CD.
If your computer doesn’t automatically do so, you might need to press the F12 key to bring up the boot
menu, but be careful not to hold it down – that can cause an error message.
13
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
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. So, if
you set up your wireless network at this point, it’s worth then clicking the Back button to go back to
the last screen (Preparing to install Ubuntu) and ticking the box marked ’Download updates while
installing’.
14
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Use the checkboxes to choose whether you’d like to Install Ubuntu alongside another operating system,
delete your existing operating system and replace it with Ubuntu, or — if you’re an advanced user —
choose the ’Something else’ option
Depending on your previous selections, you can now verify that you have chosen the way in which
you would like to install Ubuntu. The installation process will begin when you click the Install Now
button.Ubuntu needs about 4.5 GB to install, so add a few extra GB to allow for your files.
15
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
If you are connected to the internet, this should be done automatically. Check your location is correct
and click ’Forward’ to proceed. If you’re unsure of your time zone, type the name of the town you’re
in or click on the map and we’ll help you find it.
Click on the language option you need. If you’re not sure, click the ’Detect Keyboard Layout’ button
for help.
16
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
17
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
All that’s left is to restart your computer and start enjoying Ubuntu!
Conclusion: Student will understand to install Windows Operating System and Linux Operating
System Successfully.
18
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Aim:- Implementation of FCFS scheduling algorithms to find turnaround time and waiting
Time.
Theory:-
FCFS scheduling :-First Come First Serve (FCFS) is an operating system scheduling algorithm that
automatically executes queued requests and processes in order of their arrival. It is the easiest and
simplest CPU scheduling algorithm. In this type of algorithm, processes which requests the CPU first
get the CPU allocation first. This is managed with a FIFO queue. The full form of FCFS is First Come
First Serve.
Algorithm
Example:
19
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Consider the above set of processes that arrive at time zero. The length of the CPU burst time given in
millisecond.
Now we calculate the average waiting time, average turnaround time and throughput.
Average Waiting Time
First of all, we have to calculate the waiting time of each process.
Waiting Time = Starting Time - Arrival Time
Waiting time of
P1 = 0
P2 = 5 - 0 = 5 ms
P3 = 29 - 0 = 29 ms
P4 = 45 - 0 = 45 ms
P5 = 55 - 0 = 55 ms
Average Waiting Time = Waiting Time of all Processes / Total Number of Process
Therefore, average waiting time = (0 + 5 + 29 + 45 + 55) / 5 = 25 ms
Average Turnaround Time
First of all, we have to calculate the turnaround time of each process.
Turnaround Time = Waiting time in the ready queue + executing time + waiting time in waiting-queue
for I/O
Turnaround time of
P1 = 0 + 5 + 0 = 5ms
P2 = 5 + 24 + 0 = 29ms
P3 = 29 + 16 + 0 = 45ms
P4 = 45 + 10 + 0 = 55ms
P5 = 55 + 3 + 0 = 58ms
Average Turnaround Time = (Total Turnaround Time / Total Number of Process)
20
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Conclusion: Student will implement First Come First Serve Algorithm and get the desired Result.
21
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Aim:-Implementation of SJF scheduling algorithms to find turnaround time and waiting Time.
Theory:-
SJF scheduling:- It is an algorithm in which the process having the smallest execution time is chosen
for the next execution. This scheduling method can be preemptive or non-preemptive. It significantly
reduces the average waiting time for other processes awaiting execution. The full form of SJF is
Shortest Job First.
1 Preemptive:- In Preemptive SJF Scheduling, jobs are put into the ready queue as they come. A
process with shortest burst time begins execution. If a process with even a shorter burst time arrives,
the current process is removed or preempted from execution, and the shorter job is allocated CPU
cycle.
2 Non-Preemptive:- In non-preemptive scheduling, once the CPU cycle is allocated to process, the
process holds it till it reaches a waiting state or terminated.
Algorithm
1. Enter number of processes.
6. For all the next processes i, find waiting time by adding burst time of all the previously completed
process.
22
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Example:
According to the SJF Gantt chart and the turnaround time formulae,
Turnaround Time of
P1 = 3 + 5 = 8ms
P2 = 34 + 24 = 58ms
P3 = 18 + 16 = 34ms
P4 = 8 + 10 = 18ms
P5 = 0 + 3 = 3ms
Throughput
Here, we have a total of five processes. Process P1, P2, P3, P4, and P5 takes 5ms, 24ms, 16ms,
10ms, and 3ms to execute respectively. Therefore, Throughput will be same as above problem i.e.,
11.6ms for each process.
Conclusion: Student will implement Shortest Job First Algorithm and get the desired Result.
23
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
● Once a process is executed for a given time period, it is preempted and other process executes
for a given time period.
Algorithim
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where No. of time slice for process (n) = burst
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate a) Waiting time for process (n) = waiting
time of process(n-1)+ burst time of process(n-1 ) + the time difference in getting the CPU
fromprocess(n-1) b) Turnaround time for process(n) = waiting time of process(n) + burst time of
Step 7: Calculate c) Average waiting time = Total waiting Time / Number of process d) Average
24
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Quantum=5
For finding Average Waiting Time, we have to find out the waiting time of each process.
Waiting Time of
P1 = 0 + (15 - 5) + (24 - 20) = 14ms
P2 = 5 + (20 - 10) = 15ms
P3 = 10 + (21 - 15) = 16ms
Turnaround Time of
P1 = 14 + 30 = 44ms
P2 = 15 + 6 = 21ms
P3 = 16 + 8 = 24ms
Throughput
Conclusion: Student will implement Round Robin Algorithm and get the desired Result.
25
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Aim:- Implementation of Priority scheduling algorithms to find turnaround time and waiting
Time.
Theory:-
Priority scheduling :-
● Priority scheduling is a non-preemptive algorithm and one of the most common scheduling
algorithms in batch systems.
● Each process is assigned a priority. Process with highest priority is to be executed first and so
on.
● Processes with same priority are executed on first come first served basis.
● Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
Algorithim
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround time
Step 8: for each process in the Ready Q calculate a) Waiting time(n)= waiting time (n-1) + Burst
time (n-1) b) Turnaround time (n)= waiting time(n)+Burst time(n)
26
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 9: Calculate c) Average waiting time = Total waiting Time / Number of process d) Average
Turnaround time = Total Turnaround Time / Number of process Print the results in an order.
Step10: Stop
Conclusion: Student will implement Priority Scheduling Algorithm and get the desired Result.
27
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Introduction
VirtualBox allows you to run an entire operating system inside another operating system. Please be
aware that you should have a minimum of 512 MB of RAM. 1 GB of RAM or more is recommended.
● The size of the installation doesn't have to be predetermined. It can be a dynamically resized
virtual hard drive.
● You do not need to reboot in order to switch between Ubuntu and Windows.
● The virtual machine will use your Windows internet connection, so you don't have to worry
about Ubuntu not detecting your wireless card, if you have one.
● The virtual machine will set up its own video configuration, so you don't have to worry about
installing proprietary graphics drivers to get a reasonable screen resolution.
● You always have Windows to fall back on in case there are any problems. All you have to do
is press the right Control key instead of rebooting your entire computer.
● For troubleshooting purposes, you can easily take screenshots of any part of Ubuntu (including
the boot menu or the login screen).
● It's low commitment. If you later decide you don't like Ubuntu, all you have to do is delete the
virtual hard drive and uninstall VirtualBox.
● In order to get any kind of decent performance, you need at least 512 MB of RAM, because
you are running an entire operating system (Ubuntu) inside another entire operating system
(Windows). The more memory, the better. I would recommend at least 1 GB of RAM.
● Even though the low commitment factor can seem like an advantage at first, if you later decide
you want to switch to Ubuntu and ditch Windows completely, you cannot simply delete your
Windows partition. You would have to find some way to migrate out your settings from the
virtual machine and then install Ubuntu over Windows outside the virtual machine.
● Every time you want to use Ubuntu, you have to wait for two boot times (the time it takes to
boot Windows, and then the time it takes to boot Ubuntu within Windows).
28
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
During the installation wizard, you’ll get a Network Interfaces warning.. Click Yes to proceed. If
you’re in the process of downloading or copying files and data, this will interrupt your network
connection briefly. So, maybe pause the process or wait until you’re done before installing VirtualBox.
29
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
When prompted with a message to install (Trust) Oracle Universal Serial Bus, click Install to continue.
30
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
After that, VirtualBox should be installed. When you’re done installing, open VirtualBox and install
its extension pack.
The extension pack extends the functionality of VirtualBox base packages. It provides the following
enhancements to VirtualBox:
To install the extension pack, go back to VirtualBox’s download page , download and save the current
pack for all supported platforms’
Step 2: Install VirtualBox extension pack.
After downloading the saving he extension pack. open VirtualBox host software click File –>
Preferences
Then select extension, click the browse button to the right to find the download extension pack. Select
it, agree to the licensing terms and install.
31
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
When you’re done, VirtualBox software will be ready to use and install guest operating systems.
32
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 1: After you launch VirtualBox from the Windows Start menu, click on New to create a new
virtual machine. When the New Virtual Machine Wizard appears, click Next.
Step 2: You can call the machine whatever you want. If you're installing Ubuntu, it makes sense to
call it Ubuntu, I guess. You should also specify that the operating system is Linux.
33
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 3: VirtualBox will try to guess how much of your memory (or RAM) to allocate for the virtual
machine. If you have 1 GB or less of RAM, I would advise you stick with the recommendation. If,
however, you have over 1 GB, about a quarter your RAM or less should be fine. For example, if you
have 2 GB of RAM, 512 MB is fine to allocate. If you have 4 GB of RAM, 1 GB is fine to allocate. If
you have no idea what RAM is or how much of it you have, just go with the default.
Click Next.
Step 4: If this is your first time using VirtualBox (which it probably is if you need a tutorial on how to
use it), then you do want to Create new hard disk and then click Next.
34
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 6: Theoretically, a dynamically expanding virtual hard drive is best, because it'll take up only
what you actually use. I have come upon weird situations, though, when installing new software in a
virtualized Ubuntu, in which the virtual hard drive just fills up instead of expanding. So I would
actually recommend picking a Fixed-size storage.
Step 7: Ubuntu's default installation is less than 3 GB. If you plan on adding software or downloading
large files in your virtualized Ubuntu, you should tack on some buffer.
35
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 8: Click Create and wait for the virtual hard drive to be created. This is actually just a very large
file that lives inside of your Windows installation.
36
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 1: The next thing to do to make the (currently blank) virtual hard drive useful is to add the
downloaded Ubuntu disk image (the .iso) boot on your virtual machine. Click on Settings and Storage.
Then, under CD/DVD Device, next to Empty, you'll see a little folder icon. Click that.
37
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 4: You may get a bunch of random warnings/instructions about how to operate the guest operating
system within VirtualBox. Read those, and then you may also want to mark not to see those again.
38
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Step 6: Once it's started up, just follow the regular installation procedure as if you were installing.
Conclusion: Student will install Virtual Box and implement virtualization at the end of Experiment.
39
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Aim:- LINUX, file system, creating, copying, removing, renaming, and moving files in LINUX
operating system.
Objective:-
Theory:-
FILE SYSTEM:- It is used to control how data is stored and retrieved. Without a file system,
information placed in a storage area would be one large body of data with no way to tell where one
piece of information stops and the next begins.
There are many different kinds of file systems. Each one has different structure and logic,
properties of speed, flexibility, security, size and more. Some file systems have been designed to be
used for specific applications. For example, the ISO 9660 file system is designed specifically for
optical discs.
File systems can be used on many different kinds of storage devices. Each storage device uses a
different kind of media. The most common storage device in use today is a hard drive whose media is
a disc that has been coated with a magnetic film. In some cases, the computer's main memory (RAM)
is used to create a temporary file system for short term use
File system types can be classified into disk/tape file systems, network file systems and special-purpose
file systems.
40
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
1. Disk file systems:-A disk file system takes advantages of the ability of disk storage media to
randomly address data in a short amount of time. This permits multiple users access to various data on
the disk without regard to the sequential location of the data. Examples include FAT, exFAT, NTFS,
HFS and
2. Flash file systems:- A flash file system considers the special abilities, performance and restrictions
of flash memory devices. Frequently a disk file system can use a flash memory device as the underlying
storage media but it is much better to use a file system specifically designed for a flash device.
3. Tape file systems:- A tape file system is a file system and tape format designed to store files on tape
in a self-describing form. Magnetic tapes are sequential storage media with significantly longer
random data access times than disks, posing challenges to the creation and efficient management of a
general-purpose file system.
4. Database file systems:- Another concept for file management is the idea of a database-based file
system. Instead of, or in addition to, hierarchical structured management, files are identified by their
characteristics, like type of file, topic, author, or similar. Very large file systems, embodied by
applications like Apache Hoodoo and Google File System, use some database file system concepts.
5. Transactional file systems:-Transaction processing introduces the isolation guarantee, which states
that operations within a transaction are hidden from other threads on the system until the transaction
commits, and that interfering operations on the system will be properly serialized with the transaction..
This means that if there is a crash or power failure, after recovery, the stored state will be consistent.
6. Network file systems:- A network file system is a file system that acts as a client for a remote file
access protocol, providing access to files on a server. Examples of network file systems include clients
for the NFS, AFS, SMB protocols, and file-system-like clients for FTP and WebDAV.
7. Shared disk file systems:- A shared disk file system is one in which a number of machines (usually
servers) all have access to the same external disk subsystem (usually a SAN). The file system arbitrates
access to that subsystem, preventing write collisions. Examples include GFS2 from Red Hat, GPFS
from IBM, SFS from Dataflow, CXFS from SGI and StorNext from Quantum Corporation.
41
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
(1) FAT:- File Allocation Table FAT is supported by almost all operating systems for personal
computers, including all versions of Windows and MS-DOS/PC DOS and DR-DOS. SCP86-
DOSDigital Research Concurrent DOSCP/M-86The FAT file systems are therefore well-suited as
a universal exchange format between computers and devices of most any type and age. Over the
years, the file system has been expanded from FAT12 to FAT16 and FAT32. Various features have
been added to the file system including subdirectories, codepage support, extended attributes, and
long filenames.
The FAT12 and FAT16 file systems had a limit on the number of entries in the root directory of
the file system and had restrictions on the maximum size of FAT-formatted disks or partitions.FAT32
addresses the limitations in FAT12 and FAT16, except for the file size limit of close to 4 GB, but it
remains limited compared to NTFS.
(2) NTFS:- NTFS, introduced with the Windows NT operating system in 1993, allowed ACL-based
permission control. Other features also supported by NTFS include hard links, multiple file
streams, attribute indexing, quota tracking, sparse files, encryption, compression, and reparse
points (directories working as mount-points for other file systems, symlinks, junctions, remote
storage links
(3) exFAT:- exFAT is a proprietary and patent-protected file system with certain advantages over
NTFS with regard to file system overhead.exFAT is not backward compatible with FAT file
systems such as FAT12, FAT16 or FAT32. The file system is supported with newer Windows
systems, such as Windows Server 2003, Windows Vista, Windows 2008, Windows 7, Windows
8, and more recently, support has been added for Windows XP.[20]exFAT is supported in Mac OS
X starting with version.
● To study commands for creating files : TOUCH and CAT
(1) Touch :-The touch command allows users to make files using the Linux CLI. Just as the
mkdir command makes directories, the touch command makes files. Just as you would
make a .doc or a .txt using a PC desktop, the touch command makes empty files.
Syntax: - touch file name
Touch file 1 file 2 …….n
42
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
(2) CAT:-This command is used to display the contents of a file. You can read the content of a file
using cat command. Because by using command touch can can’t be able to write on a file you
can only able to create a new empty file .That’s why by using cat command we can write on
our new file.
Syntax for this command:- cat > file name
Example:- $ cat > a4
This mean we are writing something in file a4 then we save the content by using ctrl d .
If we want to see the content of file a4 then we write command $cat a4 .
We can also copy multiple files .
Example:- cat a4 a5 > b1
This mean we are copying contents of both file a4 and a5 into file b1.
● To study commands for copying file in Linux : CP
(1)Cp command:-This command is used to copy file and directory. Whenever we want to copy
content of one file to another then we use this command. The cp command makes a copy of a
file for you.
For example:- cp file footmarks an exact copy of the file whose name you entered and name
the copy too, but the first file will still exist with its original name. After you use mv, the
original file no longer exists, but after you use cp, that file stays and a new copy is made.
43
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Cp file 1 file 2
Example:- cp a4 a5
This command means we are copying content of file a4 to file a5.
● To study command for Removing ,Renaming and Moving file : RM ,MV
(1) MOVING COMMAND :- MV
The MV command - move - allows a user to move a file to another folder or directory. MV
command can be used to move any number of files and folders in a single command.
The syntax is as follows:-
mv source target
mv folder1 folder2 target
mv folder1 file1 target
mv -option source target
(2) RENAMING COMMAND :-In order to rename a file in Linux you can use either of two
approaches
(A) Create a copy of the existing file with the new desired name and then delete the old Rename
with copy and delete.
This creates a copy of the same file with a new name in the same location.
$ rm oldfile
44
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
This will delete the old file keeping the newfile intact file.
EXAMPLE:-
Rename by moving
This just moves the old file, to a new name. rm [option(s)] file(s)
Removes the specified files from the file system. Directories are not removed by rm unless the
option -r is used.
-r Deletes any existing subdirectories . -I Waits for confirmation before deleting each file
Renaming a directory in Linux and Unix is similar to renaming a file. All we need to do is replace the
file name with the directory name that is to be renamed.
For example, if we wanted to rename the directory “RR1″ to “ST1″, then we can use the following
command.
$ mv RR1 ST1
rm testfile.txt
The aforementioned command removed testfile.txt. Interestingly, whereas the rmdir
command will only delete an empty directory, the rm command will remove both files and
45
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
directories with files in it. This said, the rm command carries more weight than the rmdir
command and should be used with more specificity.
● To study the commands for listing files and directory: ls , ls-a , ls-l , ls using wild cards.
Basically ls means listing files .so files can be hidden , it can be long listing ,or it can be existing
files so that’s why ls command can be used in many ways i.e.
1. Ls
2. Ls – a
3. Ls – l
4. Ls - a – l
5. Ls using wild cards
1. LS COMMAND: - This command is used for showing exixting all files and directory
,when ever we want to see saved files and directory we always use ls command
for it .it shows file with different colors like blue color shows directories and
while colour shows files .
2. LS – A COMMAND:- This command is used to listing out all hidden files. That’s why
for viewing hidden files we use ls- a command.sometime we hide our file for preveting
its viewing that’s why to see hidden files we use this command.
46
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
3. LS- L COMMAND :- This command is used for viewing long listing files , it means it
shows a long list of many no of files .
4. LS – A - L COMMAND :- This command is used to show both hidden files and long
listing files.
5. LS COMMAND USING WILD CARDS :- ls command can be used with wild cards in
following ways
● Ls a*:- this command list out all files which are saved by name starting with a letter . we can
also use another alphabet using same command inspite of writing any alphabet at place of a.
● Ls a ? : - This command is used to list out those files whose first letter are saved with alphabet
a and that file consist of only two alphabets ..
● Ls a??:- this another command of ls using wild cards that shows file whose first letter is starting
with a and file contains three alphabets .
● To study commands for changing permission of files:chmod
1. MKDIR COMMAND: - This command is used to make directory .mk stand for make
and dir stand for directory.
2. RMDIR COMMAND:- This command is used to remove directory. whenever we have
no of saved directory are existing and when we want to remove one of them then we
47
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
us this command along with rmdir we write the name of directory to whom we want to
remove .
Conclusion: Student will execute various commands and get the desired results.
48
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Aim:- To work on miscellaneous commands in Linux. (Logname, Who, who am I, date, cal, wc,
sort, grep).
OBJECTIVE:- To study commands :logname ,who ,who am I ,date , time , cal , wc , sort , grep .
(1) LOGNAME COMMAND:- This command tells the user name on which we are working .
(2) WHO COMMAND:- This display all user name that are working on our computer.
(3) WHO AM I COMMAND :- This command used to display name of current user.
(4) DATE COMMAND:- this commands tell current user details only .
(6) WC COMMANMD:- WC means word count . Thisa command counts the no of lines and no
of characters .
(7) SORT COMMAND:- This is very important command .this command is used to sort inside
file details accordingly.
(8) GREP COMMAND:- This command is also very important command .GREP means globally
search a regular expression and print it .By using this command we can search single letter in
file and also can search through line content in a file .
Conclusion: Student will execute miscellaneous commands and get the information about
word count ,sort and who is login into the system.
49
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
OBJECTIVES:-
SHELL:-Shell provide a environment where users can runs its commands ,programs ,and shell script.
SHELL SCRIPT:-shell script is a computer program designed to be run by the Unix shell, a command
line interpreter.[1] The various dialects of shell scripts are considered to be scripting languages.
Typical operations performed by shell scripts include file manipulation, program execution, and
printing text.
● Perhaps the biggest advantage of writing a shell script is that the commands and syntax are
exactly the same as those directly entered at the command line.
● On the other hand, shell scripting is prone to costly errors.
● Another significant disadvantage is the slow execution speed and the need to launch a new
process for almost every shell command executed.
ECHO:- this command is used when we want to display the content as it is written .this comman
dwill display sentence or word as is.
50
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
ARITHMATIC COMMANDS:- these are command for solving arithmetic expressions like
addition (+) ,subtraction(-),multiplication(\*) etc.for solving arithmetic expresiion we need
command like EXPR .
Outcome: Students will learn the creation of script, various arithmetic expressions and read values
from the script.
51
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
OBJECTIVE:-
✔ EXAMPLE:- If………..then……….fi
✔ If………..then….. ..else……..fi
52
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Conclusion: Students will learn the various statements and loops and implement program using these
statements.
53
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
ALGORITHM:
• Use expr command inclosed with brackets and start with dollar symbol. sum=$ (expr $num1 +
$num2)
• This is my preferred way to directly with the shell. sum=$ ( ($num1 + $num2))
To write a shell program to check whether the given number is prime or not.
ALGORITHM:
54
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
STEP 4: If the value of i is greater than 1 then calculate „n=expr $n \* $i‟ and „i=expr $i – 1‟
Conclusion: Student will implement different shell programs and get the desired results.
55
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
ALGORITHM:
Step-3: Read the number of process, resources, allocation matrix and available matrix.
Step-4: Compare each and every process using the banker‟s algorithm.
Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a
deadlock process
Working:
1. There are two vectors Wok and Finish of length m and n in a safety algorithm.
2. Check the availability status for each type of resources [i], such as:
Finish[i] == false
56
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Finish[i] = true
Go to step 2 to check the status of resource availability for the next process.
4. If Finish[i] == true; it means that the system is safe for all processes.
A resource request algorithm checks how a system will behave when a process makes each type of
resource request in a system as a request matrix.
Let create a resource request array R[i] for each process P[i]. If the Resource Requesti [j] equal to 'K',
which means the process P[i] requires 'k' instances of Resources type R[j] in the system.
1. When the number of requested resources of each type is less than the Need resources, go to step 2
and if the condition fails, which means that the process P[i] exceeds its maximum claim for the
resource. As the expression suggests:
Go to step 2;
2. And when the number of requested resources of each type is less than the available resource for
each process, go to step (3). As the expression suggests:
Else Process P[i] must wait for the resource since it is not available for use.
57
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
When the resource allocation state is safe, its resources are allocated to the process P(i). And if the ew
state is unsafe, the Process P (i) has to wait for each type of Request R(i) and restore the old resource-
allocation state.
Conclusion: Students will learn the Bankers Algorithm and implement the same to get desired results.
58
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Experiment No.:- 7
Aim: Implementation of Reader-writer problem using Semaphores
• If one of the person tries editing the file, no other person should be reading or writing at the
same time, otherwise changes will not be visible to him/her.
• However if some person is reading the file, then others may read it at the same time.
readers-writers problem
Problem parameters:
Here priority means, no reader should wait if the share is currently opened for reading.
59
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Writer process:
do {
wait(wrt);
signal(wrt);
} while(true);
Reader process:
60
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
do {
wait(mutex);
readcnt++;
readcnt--;
} while(true);
Thus, the semaphore ‘wrt‘ is queued on both readers and writers in a manner such that
preference is given to readers if writers are also there. Thus, no reader is waiting simply because
a writer has requested to enter the critical section.
Conclusion: Students will learn the Reader Writer Problem implement the same and get desired
results.
61
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Experiment No.:- 8
Aim: Implementation of FCFS Disk Scheduling Algorithm.
= (176-50)+(176-79)+(79-34)+(60-34)+(92-60)+(92-11)+(41-11)+(114-41)
= 510
Conclusion: Students will learn FCFS Disk Algorithm and implement the same to get desired results.
62
Chandigarh Engineering College-CGC
Landran, Mohali, Punjab
Experiment No.:--9
Aim: Implementation of SSTF Disk Scheduling Algorithm
Example –
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
The following chart shows the sequence in which requested tracks are serviced using SSTF.
Therefore, total seek count is calculated as:
= (50-41)+(41-34)+(34-11)+(60-11)+(79-60)+(92-79)+(114-92)+(176-114)
= 204
Conclusion: Students will learn Shortest Seek Time First Algorithm and find out the Seek Time and
get the desired results.
63