OS Lab
OS Lab
OS Lab
on
UGCA 1926 : Operating Systems Lab
Program Outcomes
Requirements:
Display: 800x600.
To change the UEFI boot settings on Windows 10, use these steps:
1. Open Settings.
2. Click on Update & Security.
3. Click on Recovery.
5. Click the Troubleshoot button.
6. Click on Advanced options.
10. Set the boot order to start from the USB flash drive with the
Windows 10 installation files.
Save the changes.
After you complete the steps, the computer should now be able to
start from a USB bootable media.
Once you went through the preparation instructions, the clean install of
Windows 10 is actually a straightforward process.
Quick tip: If your language, time and currency, and keyboard are different
from the default selections, make sure to select the correct settings before
continuing.
4. Click the Install now button.
5. If you're doing a reinstallation, click the I don't have a product
key option to continue (assuming that your device was already activated).
Otherwise, in the case that this is your first time installing Windows 10, enter
the product key.
6. Click the Next button.
7. Select the edition of Windows 10 (If applicable).
Quick note: This selection must match the edition that the product key
activates. If you don't select the correct edition, Windows 10 won't activate,
and you'll have to redo the entire process one more time.
8. Click the Next button.
9. Select the I accept the license terms option to continue.
10. Click the Next button.
11. Click the Custom: Install Windows only (Advanced) option to continue
with a clean installation.
12. Select the partition with the current installation (usually "Drive 0"), and
click the Delete button.
Quick tip: If "Drive 0" has multiple partitions, you have to select and delete
each partition to allow the setup to use the entire hard drive for the new clean
installation. The Windows 10 setup will create the required partitions
automatically during the process. Also, it's not necessary to delete the
partitions on secondary drives.
13. Click the Yes button.
14. Select the empty drive (Drive 0 Unallocated Space).
15. Click the Next button.
Once you complete the steps, the setup will install a fresh copy of Windows 10
on the computer.
Practical 2
Aim: Installation of linux operating system
Once you download the ISO file, you will have to burn it on DVD or the
easy way, copying it on a USB stick using a program called Universal
USB installer, you can download this program from google
After downloading the application, open it and choose from the list the
distro you want to install; in our case, we will select Linux mint.
Make sure that you put your memory stick on the computer and click
next and wait till the copying process is finished.
Now Finally we click create to create bootable USB
And now you can boot with this memory stick.
Then Restart your PC and go to BIOS settings and select boot options
and make sure that the USB is the first option, then save your BIOS
settings and reboot.
Then it will show the installation screen, press Enter, and it will load the
live CD content.
Now the desktop should appear like that:
Click install Linux Mint.
If you are installing it on a new disk, choose the option Erase disk.
Now we will create them by clicking the plus button and choose about 12
GB or more as you need but not less than that for the root partition and
choose mount type as / which stands for root and of course format will
be Ext4.
Now we create a swap partition, choose the remaining free space and
click the plus button and choose the swap area as shown:
Then Create the swap area:
Then click install now and agree about writing changes to disk:
Now you choose the time zone and click continue the choose the
language:
Now you write your username and password and click continue:
Finally, the installation started:
After finishing the installation, it will prompt you to reboot the machine
and remove the installation media, whether it is a DVD or USB.
Practical 3
Aim Dual boot 2 operating systems
Follow the steps below to install Linux Mint in dual boot with Windows:
Go to Linux Mint website and download ISO file. This ISO file is the disk image that you can
burn to a USB or DVD.
There are several versions of Linux Mint available. The default is Cinnamon. If your computer
supports 64 bit, go with 64 bit Linux Mint 19.3 Cinnamon. If you know about other desktop
environments, you can make your mind and choose whichever Mint version you want.
Once you have downloaded the Linux Mint ISO, you need a tool to write the image to a disk. I
recommend using a free tool called Universal USB Installer in Windows:
It’s an executable exe file. Just double click on it to run the software and browse it to the ISO.
Make sure that you have your USB key plugged in:
This is where you have to be cautious. If you have multiple partitions (not the recovery ones),
you can either use one of them or create a new partition from an existing partition. Your existing
data will be safe if you have enough free space. Typically, you install Linux in under 10 Gb,
however, if disk space if not a concern, I advise using 30-40Gb at least. This way you can have
more space at your disposal for downloading and keeping various files.
In Windows 10, go to start menu and type ‘partition’. This will bring up Disk Management
utility. Now carefully select the disk in which you’ll make some free space by shrinking the
volume:
In my case, I only had the C Drive with 223Gb of space on it. So I shrunk it to make 110Gb of
free partition on it. I recommend watch the video to see the exact steps you need more hint.
Plug the live USB or disk into the computer and restart the computer. While booting the
computer press F10 or F12 function key (defers fom computer to computer) to go to the boot
menu. Now, choose the option to boot from USB or Removable Media.
Important Note: If your computer came with Windows 8 or Windows 8.1 and you upgraded
your system to Windows 10, you may have to disable secure boot. Most modern system with
Windows 10 should not need this step, especially with Linux Mint or Ubuntu.
It takes some time to boot from the live USB or disk. Have some patience. Once it boots in to
live disk, you’ll be provided to Try Linux Mint or Install Linux Mint. Even if you choose to try
it, you can find the install option on the desktop:
In next few screens, you’ll be asked to choose the language of the operating system. It will then
do some checks on available space, battery and Internet connection.
This is the most important part of the whole installation. Where to install Linux Mint?
If you see the option to Install Linux Mint alongside Windows, you can select that. Linux Mint
will handle things on its own. If you do that, skip step 5 and step 6.
But as mentioned before, I prefer separate partitions for Windows and Linux. Windows is
already installed here, we’ll prepare a new partition for Linux Mint. In the Installation Type
window, choose Something Else:
Since you already created a new partition in Windows, it’s time to install Linux Mint on it. Now,
there are several ways to do it. But here, I’ll show you my favorite way and that is to have a
Root, a Swap and a Home.
Create a root partition first. Choose the free space available and click on +.
Here, choose the size of the root. Root is like your C drive in Windows. Installed software,
updates and other system files are under this root partition. Home partition is for your personal
documents, music, downloads etc.
If you have total 100 GB at disposal, give 30 GB to root. In any case, don’t give it less than 15
GB because if root runs out of space, your system will slow down and you’ll run into issues.
I opted to have 20 GB, choose ext4 file system, and mount point as / (i.e. root):
RAM less than 2 GB: Swap should be double the size of RAM
RAM between 2 to 4 GB: Swap should be RAM size + 2 GB
RAM between 6 GB to 8 GB: Swap should be size of RAM
RAM more than 8 GB: Swap should be half the size of RAM or less
Don’t spend too much time thinking about swap. It is helpful for systems with less memory. For
system with more than 8 GB of RAM and SSD, the less the swap, the better it is.
Newer version of Linux Mint utilize Swap file. It creates a special file under root and utilizes it
as swap area. You can have both swap partition and swap file in a system.
The next step is to create Home. Try to allocate the maximum size to Home because this is
where you’ll be downloading and keeping the files.
Once you have created Root, Swap and Home partitions, click on Install Now button.
Technically, you have crossed the main hurdle if you reached this point successfully. Now you
will be taken through a number of screens to select options like keyboard layout, login
credentials etc. You don’t need to be a genius to figure out what to do here afterward. I have
attached screenshots for reference purpose here.
Once the installation is over, you will be presented with the option to keep trying live version or
to restart the system.
Practical 4
As the process enters the ready queue, its PCB (Process Control Block)
is linked with the tail of the queue and, when the CPU becomes free, it
should be assigned to the process at the beginning of the queue.
P1 6
P2 3
P3 8
P4 3
P5 4
P1 6
P2 3
P3 8
P4 3
P5 4
Step 2) At time= 2, P1 arrives which is kept in the queue.
P1 6
P2 3
P3 8
P4 3
P5 4
Step 3) At time=3, P4 process completes its execution.
Step 4) At time=4, P3, which is first in the queue, starts execution.
P1 6
P2 3
P3 8
P4 3
P5 4
P1 6
P2 3
P3 8
P4 3
P5 4
Step 10) Let's calculate the average waiting time for above example.
Waiting time = Start time - Arrival time
P4 = 0-0 = 0
P3 = 3-1 = 2
PI = 11-2 = 9
P5= 17-4 = 13
P2= 21-5= 16
= 40/5= 8
Advantages of FCFS
Disadvantages of FCFS
Non-Preemptive SJF
Preemptive SJF
In non-preemptive scheduling, once the CPU cycle is allocated to process, the process holds it
till it reaches a waiting state or terminated.
Consider the following five processes each having its own unique
burst time and arrival time.
P2 2
P3 8
P4 3
P5 4
Step 0) At time=0, P4 arrives and starts execution.
Step 2) At time =2, process P1 arrives and is added to the waiting
queue. P4 will continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time
of P3 and P1 is compared. Process P1 is executed because its burst
time is less compared to P3.
Step 4) At time = 4, process P5 arrives and is added to the waiting
queue. P1 will continue execution.
Step 6) At time = 9, process P1 will finish its execution. The burst time
of P3, P5, and P2 is compared. Process P2 is executed because its burst
time is the lowest.
Step 7) At time=10, P2 is executing and P3 and P5 are in the waiting
queue.
Step 8) At time = 11, process P2 will finish its execution. The burst
time of P3 and P5 is compared. Process P5 is executed because its
burst time is lower.
Step 11) Let's calculate the average waiting time for above example.
Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14
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.
P1 6
P2 2
P3 8
P4 3
P5 4
P1 6
P2 2
P3 8
P4 3
P5 4
Step 1) At time= 1, Process P3 arrives. But, P4 has a shorter burst time.
It will continue execution.
Step 2) At time = 2, process P1 arrives with burst time = 6. The burst
time is more than that of P4. Hence, P4 will continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time
of P3 and P1 is compared. Process P1 is executed because its burst
time is lower.
Step 4) At time = 4, process P5 will arrive. The burst time of P3, P5,
and P1 is compared. Process P5 is executed because its burst time is
lowest. Process P1 is preempted.
Process Queue Burst time
P1 5 out of 6 is remaining
P2 2
P3 8
P4 3
P5 4
Step 5) At time = 5, process P2 will arrive. The burst time of P1, P2, P3,
and P5 is compared. Process P2 is executed because its burst time is
least. Process P5 is preempted.
P1 5 out of 6 is remaining
P2 2
P3 8
P4 3
P5 3 out of 4 is remaining
Step 7) At time =7, P2 finishes its execution. The burst time of P1, P3,
and P5 is compared. Process P5 is executed because its burst time is
lesser.
Process Queue Burst time
P1 5 out of 6 is remaining
P2 2
P3 8
P4 3
P5 3 out of 4 is remaining
Step 8) At time =10, P5 will finish its execution. The burst time of P1
and P3 is compared. Process P1 is executed because its burst time is
less.
Step 9) At time =15, P1 finishes its execution. P3 is the only process
left. It will start execution.
Wait time
P4= 0-0=0
P1= (3-2) + 6 =7
P2= 5-5 = 0
P5= 4-4+2 =2
P3= 15-1 = 14
Process Queue
P1
P2
P3
Step 1) The execution begins with process P1, which has burst time 4.
Here, every process executes for 2 seconds. P2 and P3 are still in the
waiting queue.
Step 2) At time =2, P1 is added to the end of the Queue and P2 starts
executing
Step 3) At time=4 , P2 is preempted and add at the end of the queue.
P3 starts executing.
Step 4) At time=6 , P3 is preempted and add at the end of the queue.
P1 starts executing.
Step 7) Let's calculate the average waiting time for above example.
Wait time
P1= 0+ 4= 4
P2= 2+4= 6
P3= 4+3= 7
Practical 7
The default editor that comes with the UNIX operating system is
called vi (visual editor). Using vi editor, we can edit an existing file
or create a new file from scratch. we can also use this editor to just
read a text file.
q : Quit
q! : Quit without saving changes i.e. discard changes.
r fileName : Read data from file called fileName.
wq : Write and quit (save and exit).
w fileName : Write to file called fileName (save as).
w! fileName : Overwrite to file called fileName (save as
forcefully).
!cmd : Runs shell commands and returns to Command mode.
Searching and Replacing in (ex Mode): vi also has powerful
search and replace capabilities. The formal syntax for searching is:
:s/string
Practical 8
Command Description
Command Description
Command Description
File Editors
Command Description
Command Description
Manipulating data
The contents of files can be compared and altered with the following
commands.
Command Description
Command Description
Command Description
tr translate characters
A variable is nothing more than a pointer to the actual data. The shell
enables you to create, assign, and delete variables.
Variable Names
The name of a variable can contain only letters (a to z or A to Z),
numbers ( 0 to 9) or the underscore character ( _).
By convention, Unix shell variables will have their names in
UPPERCASE.
The following examples are valid variable names −
_ALI
TOKEN_A
VAR_1
VAR_2
Following are the examples of invalid variable names −
2_VAR
-VARIABLE
VAR1-VAR2
VAR_A!
The reason you cannot use other characters such as !, *, or - is that
these characters have a special meaning for the shell.
Defining Variables
Variables are defined as follows −
variable_name=variable_value
For example −
NAME="Zara Ali"
The above example defines the variable NAME and assigns the value
"Zara Ali" to it. Variables of this type are called scalar variables. A
scalar variable can hold only one value at a time.
Shell enables you to store any value you want in a variable. For
example −
VAR1="Zara Ali"
VAR2=100
Accessing Values
To access the value stored in a variable, prefix its name with the dollar
sign ($) −
For example, the following script will access the value of defined
variable NAME and print it on STDOUT −
#!/bin/sh
NAME="Zara Ali"
echo $NAME
Read-only Variables
Shell provides a way to mark variables as read-only by using the read-
only command. After a variable is marked read-only, its value cannot
be changed.
For example, the following script generates an error while trying to
change the value of NAME −
#!/bin/sh
NAME="Zara Ali"
readonly NAME
NAME="Qadiri"
#!/bin/sh
NAME="Zara Ali"
unset NAME
echo $NAME
The above example does not print anything. You cannot use the
unset command to unset variables that are marked readonly.
Variable Types
When a shell is running, three main types of variables are present −
Local Variables − A local variable is a variable that is present
within the current instance of the shell. It is not available to
programs that are started by the shell. They are set at the
command prompt.
Environment Variables − An environment variable is available
to any child process of the shell. Some programs need
environment variables in order to function correctly. Usually, a
shell script defines only those environment variables that are
needed by the programs that it runs.
Shell Variables − A shell variable is a special variable that is set
by the shell and is required by the shell in order to function
correctly. Some of these variables are environment variables
whereas others are local variables.
Practical 10
The Bourne shell syntax provides basic input with very little effort.
#!/bin/sh
read NAME
#!/bin/sh
IFS="q"
#!/bin/csh
Syntax:
1. Variable_name=value
1. Prefix the variable name with dollar ($) sign while reading or
printing a variable.
2. Leave off the dollar sign ($) while setting a variable with any
value.
an underscore (_).
4. A variable name is case-sensitive: x and X are considered as two
different variables.
(=) between the variable name and its value. Following are some
var1=...variable1
var2...=variable2
var3...=...variable3
Data Types
1. int year=2012
2. char comp_name='jtp'
But in case of Bash, you don't have to define the data type of any
variable at the time of variable declaration. Bash variables
are untyped, which means just type the variable name by assigning its
value, and it will automatically consider that data type.
Such that if you assign any numeric value to the variable, it will work
as integer and if you assign a character value to the variable, then it
will be String.
1. year=2012
2. comp_name=jtp
echo $year
echo $name
1. System-Defined Variables
2. User-Defined Variables
Example:
1. BASH=/usr/bin/bash
Example:
1. BASH_VERSION=4.2.46(2)
Example:
1. COLUMNS=80
Example:
1. HOME=/home/jatpoint
1. LOGNAME=javatpoint
Example:
1. OSTYPE=linux-gnu
Example:
1. PWD=/home/javatpoint
Example:
1. USERNAME=javatpoint
1. Typing the set command.
Output:
2. Typing the env command
Output:
3. Typing the printenv command
Output:
Let's call these variables through Bash Shell. Following are the given
steps:
1. #! /bin/bash
2. # Bash System-defined Variables
3. echo $HOME # Home Directory
4. echo $PWD # current working directory
5. echo $BASH # Bash shell name
6. echo $BASH_VERSION # Bash shell Version
7. echo $LOGNAME # Name of the Login User
8. echo $OSTYPE # Type of OS
Step 3. Save and execute the script. It will show the output as you can
see in the figure given below.
Output:
2. User-defined Variables: These variables are created and
maintained by the user. Generally, these types of variables are defined
in LOWER_CASES. There is not any strict rule to write these variables in
lower-cases. We can write them in upper-cases also.
Let's create a Bash Script to define these variables. Follow the given
steps given below:
1. #! /bin/bash
2. # User-Defined Variables
3. name=Peter
4. ROLL_NO=5245325
5. echo "The student name is $name and his Roll number is $ROLL_
NO."
Output:
Practical 12
Operator Descripti
Example
Here is an example which uses all the arithmetic operators −
#!/bin/sh
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
if statement
This block will process if specified condition is true.
Syntax:
if [ expression ]
then
statement
fi
if-else statement
If specified condition is not true in if part then else part will be
execute.
Syntax
if [ expression ]
then
statement1
else
statement2
fi
if..elif..else..fi statement (Else If ladder)
To use multiple conditions in one if-else block, then elif keyword is
used in shell. If expression1 is true then it executes statement 1 and
2, and this process continues. If none of the condition is true then it
processes else part.
Syntax
if [ expression1 ]
then
statement1
statement2
.
.
elif [ expression2 ]
then
statement3
statement4
.
.
else
statement5
fi
if..then..else..if..then..fi..fi..(Nested if)
Nested if-else block can be used when, one condition is satisfies
then it again checks another condition. In the syntax, if expression1
is false then it processes else part, and again expression2 will be
check.
Syntax:
if [ expression1 ]
then
statement1
statement2
.
else
if [ expression2 ]
then
statement3
.
fi
fi
switch statement
case statement works as a switch statement if specified value match
with the pattern then it will execute a block of that particular
pattern
When a match is found all of the associated statements until the
double semicolon (;;) is executed.
A case will be terminated when the last command is executed.
If there is no match, the exit status of the case is zero.
Syntax:
case in
Pattern 1) Statement 1;;
Pattern n) Statement n;;
esac
Example Programs
Example 1:
Implementing if statement
a=10
b=20
if [ $a == $b ]
then
fi
then
fi
Output
$bash -f main.sh
a is not equal to b
Example 2:
Implementing if.else statement
a=20
b=20
if [ $a == $b ]
then
else
Output
$bash -f main.sh
a is equal to b
Practical 14
The while loop enables you to execute a set of commands repeatedly
until some condition occurs. It is usually used when you need to
manipulate the value of a variable repeatedly.
Syntax
while command
do
Statement(s) to be executed if command is true
done
Here the Shell command is evaluated. If the resulting value is true,
given statement(s) are executed. If command is false then no
statement will be executed and the program will jump to the next line
after the done statement.
Example
Here is a simple example that uses the while loop to display the
numbers zero to nine −
#!/bin/sh
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done