practical file of Operating system
practical file of Operating system
Of
Operating system
1
Index
Sr. Experiment Page Date of Teacher
No No Submission Signature
11 41
Shell Scripting – Data types.
12 42
Shell Scripting – Use of arithmetic
operators.
2
Experiment 1: Installation of windows OS.
There are several ways to install Windows 10 on your computer system. You can easily use any
one of them. For example:
We have already described how to upgrade your existing Windows 7 or Windows 8 operating
system to Windows 10. You can see it here: File in Windows Questions 4
Here, we are going to describe how to install a fresh new Windows 10 from scratch. This option
is used when you don't want to upgrade from existing Windows and install a clean Windows
10.
Let's start to install a clean and fresh Windows 10. Follow the steps given below:
o To perform a clean installation of Windows 10, download the free official Windows 10
installation media from Microsoft. Download it from
here: https://www.microsoft.com/en-us/software-download/windows10startfresh
o You can see that the tool is downloaded now. Now, run the downloaded file.
Accept the license term. Now, you will be asked to "Give your PC a fresh start." Choose any one
of the options given below. Select what you want to keep.
3
o Now, select "Create installation media for another PC" option. See the below image:
o Select the language, architecture, and edition according to your need. For example, if
you have a laptop or PC with a 64-bit CPU, then you have to install the 64-bit version. If
you have a computer or PC with a 32-bit CPU, then you have to install the 32-bit version.
If you want to install Windows 10 on your current using laptop or PC, check the box "Use
the recommended options for this PC," and it will automatically download the best
compatible version for your current using PC; otherwise, uncheck this box. See the
image below:
4
o Now, you can copy the Windows 10 installation files to a USB drive or burn them to a
DVD. The Windows 10 installation files occupy the space greater than 3 GB so, your USB
drive must be 4 GB or larger in size. The USB drive must be empty because all files in the
USB drive will be erased in this process. You can select the "ISO file" option if you want
to install Windows 10 in a virtual machine. First, download the ISO file and then boot
the downloaded ISO in a virtual machine to install Windows 10 inside that.
o Now ,the installation media is created. Please insert it into your laptop or PC and install
Windows 10. You have to boot to the Windows 10 installer. For the booting process,
Click on the Start menu button and restart your laptop.
o Now, press and hold Del or F2 button to enter setup. This key may be different in some
computers. Generally, it is displayed as a message on startup that says, "Press [key] to
enter setup."
5
o Now, go to the "Boot" option on the above menu bar and select a device from which
you have to boot. You will see the following two option there:
1. For a USB flash drive, select the Removable Devices option.
2. For a disc installation, select the CD-ROM Drive option.
o Now, save your setting and press the Enter button to confirm the changes. Now, wait
for your PC to restart.
o Now, the installation is started. Select your language, time, and currency format on the
Windows setup screen and then click "Next" to continue.
o You may have to click on several "next" buttons, and finally, you will see the installer
screen. See the below image:
o Click on the install now button and follow the given instructions to install Windows 10
on your system successfully.
o Windows 10 is installed successfully. Now, you will see the Activate Windows screen.
You can enter a key or skip it. If installing Windows 10 automatically detects a key
associated with your PC's hardware, you will not see it on your screen.
6
o If you have a valid product key for Windows 10, you can paste it here. You can also paste
a valid Windows 7, 8, or 8.1 key here. You will get the advantage of the free Windows
10 upgrade offer on your PC.
o After that, you will see a new Windows setup screen "Which type of installation do you
want?" Click "Custom" if you want to perform a clean installation. It will remove
everything on your PC. If you want to upgrade your existing installation, click the
"Upgrade" option.
o Select the hard drive partition where you want to install Windows. It will delete the data
you have in that partition. Make sure that you have backups of any important files
before doing this.
o In this installation process, your system may restart several times. At the end of the
process, you will get a new Windows 10 as your operating system.
7
Experiment 2: Installation of Linux OS.
8
Step 4) Install Ubuntu.
Click YES to Install Ubuntu in USB.
Step 1) Download the .iso or the OS files onto your computer from this
link http://www.ubuntu.com/download/desktop.
Step 3) Boot your computer from the optical drive and follow the instructions as they come.
Virtual machine software like Oracle VM can install Linux on Windows in easy steps. Let us
look at them.
9
PART A) Download and Install Virtual Box
Depending on your processor and OS, select the appropriate package. In our case, we have
selected Windows with AMD
Once the download is complete, Open setup file and follow the steps below:
Step-2) Select you’re the directory to install VirtualBox and click on next
10
Step-3) Select Desktop icon and click on next, now click on yes
Step-5) Now installation of the virtual box will start. Once complete, click on Finish Button to
start Virtual Box
11
The virtual box dashboard looks like this-
12
Step-2) In next window, give the name of your OS which you are installing in virtual box. And
select OS like Linux and version as Ubuntu 32 bit. And click on next
Step-3) Now Allocate Ram Size To your Virtual OS. I recommended keeping 1024mb (1 GB)
ram to run Ubuntu better. And click on next.
Step-4) Now To run OS in virtual box we have to create virtual hard disk, click on create a
virtual hard drive now and click on create button.
The virtual hard disk is where the OS installation files and data/applications you create/install
in this Ubuntu machine will reside
13
Step-5) select VHD (virtual hard disk) option and click on next.
Step-6) Click on dynamic allocated and click on next. This means that the size of the disk will
increase dynamically as per requirement.
Step-7) Allocate memory to your virtual hard drive .8GB recommended. Click on create
button.
14
Step-8) Now you can see the machine name in left panel
15
Step 3) Select the Ubuntu iso file
Step-5) You have an option to Run Ubuntu WITHOUT installing. In this tutorial will install
Ubuntu
16
Step-6) Click continue.
Step-7) Select option to erase the disk and install Ubuntu and click on install now. This option
installs Ubuntu into our virtual hard drive which is we made earlier. It will not harm your PC or
Windows installation
Step-8) Select your location for setting up time zone, and click on continue
Step-9) Select your keyboard layout, by default English (US) is selected but if you want to
change then, you can select in the list. And click on continue
17
Step-10) Select your username and password for your Ubuntu admin account. This
information has been needed for installing any software package into Ubuntu and also for
login to your OS. Fill up your details and tick on login automatically to ignore login attempt
and click on continue
Step-11) Installation process starts. May take up to 30 minutes. Please wait until installation
process completes.
Step-12) After finishing the installation, you will see Ubuntu Desktop.
18
Experiment 3: Dual boot installation of Operating systems.
When two operating systems are installed on a computer system, it is called dual booting. In
fact, multiple operating systems can be installed on such a system. But how does the system
know which operating system to boot? A boot loader that understands multiple file
systems and multiple operating systems can occupy the boot space. Once loaded, it can
boot one of the operating systems available on the disk. The disk can have multiple
partitions, each containing a different type of operating system. When a computer system
turns on, a boot manager program displays a menu, allowing the user to choose the
operating system to use.
It is possible to dual boot using two different operating systems. Suppose you want to run
Windows with Linux operating system in your system. Then the user must first determine the
distribution you want to run in your system. Some popular distributions of Linux OS are Mint
and Ubuntu, with many distributions to choose from. Each distribution has its unique features
that can be used to perform different functions.
Here, we will use the Linux Mint operating system. The steps are similar for installing the
other distributions as well. The only change is that the user needs to download the disk image
associated with the Linux distribution you want to install for the dual boot. If you want to
learn more about the distribution you are using or having trouble choosing one, then you can
refer to the distribution documentation. It contains details about the installers of the Linux
distribution too.
The user can download the disk images from the internet. The images are available on the
official Linux website.
19
Go to the official website and download the image for the Linux Mint.
This step is similar to the one performed using two windows operating systems for the dual
boot. You will require an empty flash drive. If the files contain any data, the data will be lost.
The simplest way to convert your flash drive into a bootable installation media is using a
Universal USB installer. The user can download it from the official website. The website also
contains instructions about how to use the installer.
For a desktop, the simplest and most secure way to use dual boot is by purchasing and installing
a new hard, hard drive or SSD for the new operating system. This is secure and uses this method.
You won't have to compromise the space provided to the existing OS. There will be no
requirement for repartitioning either.
You can skip stepping four if you are performing dual boot in a new device. Else the user will
have to create space for installing the new Windows on your existing drive.
For Windows 10, the user needs to perform the given steps:
20
A new feature has been introduced in Windows 10. The feature is known as the Secure Boot.
This feature was introduced to ensure that there is no tampering with the installation of the
Windows OS. But if this software is enabled, this option can cause trouble when using the
dual boot with the Linux OS.
This step disables the feature which may not be necessary but depend on your hardware. Still,
it is better to disable the option as a preventive step so that this does not create any problems
in the future during installation.
Follow the below steps to turn off the secure boot in your operating system:
1. First, you will require to access the UEFI settings. UEFI is special software that is
responsible for execution on the motherboard.
2. Open the start-up menu in Windows and open the settings menu.
3. Once the setting option is opened, click on Update and Security.
4. Look in the left pane. There you will find Recovery. Click on it.
5. From the Advanced Startup, select Restart Now.
6. This will restart the system and boot up an options menu. All these tasks will be
performed before the Windows is loaded.
7. Select the troubleshooting option, and click on the advanced option.
8. Select the UEFI Firmware Settings.
9. This will open the motherboard settings menu. The setting menu can vary because it
depends upon the motherboard manufacturer. So, if visible, you turn off the secure
boot option. And if not visible, then you can use the search menu to find the option. You
should also find the motherboard manufacturer's name on the top of the motherboard
settings.
10. Press the F10 button to save the modifications that the user made. They exit the UEFI
settings.
For the next step, ensure that the USB drive you have downloaded from the Linux installer is
attached to your system.
21
Now go to the boot manager of your system. To open the boot manager:
Once you have performed the above steps, restart the system, and the boot manager will be
opened. Then use the up and down arrow keys on your keyboard to go to the USB Linux Drive.
Once you reach there, select it and click on Enter.
Perform the steps as instructed by the installer. Follow them until you reach the type screen in
the installer. Then press something else option.
You would want to split the space into at least three partitions. These three partitions are as
follows:
o /root- This is the first partition. In this space, all the operating system files are stored.
o /swap- This partition will serve as extra memory that can be used when the existing
RAM is not sufficient to run the Linux OS.
o /home- All the remaining files installed while and after installing the Linux OS are stored
in this partition.
If the user uses a new hard drive to install the operating system, then find the hard drive and
continue. Otherwise, find the free space created by the user before and use it.
22
Creating the /root partition
After selecting the space where you want to create the partitions, that is either the new drive
or the space in the existing drive. Select the + sign. Now you will see the window to create a
partition. These windows allow the user to create the main Linux partition.
In the next step, the user needs to provide space to the system that the partition will use to
store the files and programs of the operating system. The minimum recommended space for
the proper functioning of the operating system is 10 GB. It can be up to 5 GB. But if you want
to install multiple additional programs in the OS, the user will have to assign the storage
accordingly.
The size that is allotted to create the partition is entered in megabytes, so 1 GB is almost equal
to 10,000 MB.
Select the + sign. Now the user needs to create the swap partition. This will act as the temporary
RAM of the system. It is the temporary memory that is assigned when space is not available in
the system RAM. It is recommended to be of the same size as your system RAM. For example,
if your system has 8 GB RAM, assign 8000 MB space for the partition.
o Size: 8000MB
o Type for the new partition: Primary
o Location for the new partition: Beginning of this space
o Use as: swap area
You must follow the same steps above to create the home partition. This partition will be used
to store all the files and documents. This will occupy most space available on the drive. You can
assign the remaining space to the home partition.
Once you have set up the partitions, you need to click on the Install button to install the Linux
OS.
After installing, you will have to choose a time zone and the layout for the keyboard. The user
must also create a new username and password for the same.
24
Experiment 4: Implementation of FCFS scheduling algorithm.
First in, first out (FIFO), also known as first come, first served (FCFS), is the simplest scheduling
algorithm. FIFO simply queues processes in the order that they arrive in the ready queue.
In this, the process that comes first will be executed first and next process starts only after
the previous gets fully executed.
// C++ program for implementation of FCFS
// scheduling
#include<iostream>
using namespace std;
// Function to find the waiting time for all
// processes
void findWaitingTime(int processes[], int n,
int bt[], int wt[])
{
// waiting time for first process is 0
wt[0] = 0;
// calculating waiting time
for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}
// Function to calculate turn around time
void findTurnAroundTime( int processes[], int n,
int bt[], int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
//Function to calculate average time
25
void findavgTime( int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
//Function to find waiting time of all processes
findWaitingTime(processes, n, bt, wt);
//Function to find turn around time for all processes
findTurnAroundTime(processes, n, bt, wt, tat);
//Display processes along with all details
cout << "Processes "<< " Burst time "
<< " Waiting time " << " Turn around time\n";
// Calculate total waiting time and total turn
// around time
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
<< wt[i] <<"\t\t " << tat[i] <<endl;
}
cout << "Average waiting time = "
<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n;
}
// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
26
int n = sizeof processes / sizeof processes[0];
//Burst time of all processes
int burst_time[] = {10, 5, 8};
findavgTime(processes, n, burst_time);
return 0;
}
Output:
27
Experiment 5: Implementation of SJF scheduling algorithm.
The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting
process with the smallest execution time to execute next. SJN, also known as Shortest Job Next
(SJN), can be preemptive or non-preemptive.
Algorithm:
Sort all the processes according to the arrival time.
Then select that process that has minimum arrival time and minimum Burst time.
After completion of the process make a pool of processes that arrives afterward till the
completion of the previous process and select that process among the pool which is
having minimum Burst time.
28
for (i = 0; i < n; i++) {
cout << "P" << i + 1 << ": ";
cin >> A[i][1];
A[i][0] = i + 1;
}
// Sorting process according to their Burst Time.
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
cout << "P BT WT TAT" << endl;
// Calculation of Turn Around Time and printing the
// data.
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
cout << "P" << A[i][0] << " " << A[i][1] << " " << A[i][2] << " " << A[i][3]
<< endl;
}
avg_tat = (float)total / n;
cout << "Average Waiting Time= " << avg_wt << endl;
cout << "Average Turnaround Time= " << avg_tat << endl;
}
29
Output:
30
Experiment 6: Implementation of Round-Robin Scheduling algorithm.
Round Robin is a CPU scheduling algorithm where each process is cyclically assigned a fixed
time slot. It is the preemptive version of the First come First Serve CPU Scheduling
algorithm.
Implementation of code in C++:
31
rem_bt[i] -= quantum;
}
32
// Function to find turn around time for all processes
findTurnAroundTime(processes, n, bt, wt, tat);
Output:
33
Experiment 7: Vi Editor & its commands.
The vi editor is elaborated as visual editor. It is installed in every Unix system. In other words,
it is available in all Linux distros. It is user-friendly and works same on different distros and
platforms. It is a very powerful application. An improved version of vi editor is vim.
o Command Mode: In command mode, actions are taken on the file. The vi editor starts
in command mode. Here, the typed words will act as commands in vi editor. To pass a
command, you need to be in command mode.
o Insert Mode: In insert mode, entered text will be inserted into the file. The Esc key will
take you to the command mode from insert mode.
Implementation in C:
#include <stdio.h>
int main() {
printf("Welcome to Vi editor!\n");
// Insert mode: press 'i' to enter insert mode, type text, and press 'Esc' to exit insert mode
printf("This is insert mode. Press 'i' to start typing.\n");
// Save and Exit: press ':wq' and then press Enter to save and exit
printf("To save and exit, press ':wq' and then press Enter.\n");
// Move cursor: use arrow keys or 'h', 'j', 'k', 'l' for left, down, up, right respectively
printf("Use arrow keys or 'h', 'j', 'k', 'l' to move cursor.\n");
// Search: press '/' to start searching, type search query, and press Enter
printf("Press '/' to start searching, type search query, and press Enter.\n");
// Replace: press ':' to enter command mode, type 's/old_text/new_text/g' to replace all
occurrences
printf("Press ':' to enter command mode, type 's/old_text/new_text/g' to replace all
occurrences.\n");
return 0;
}
34
Output:
35
Experiment 8: Shell Commands.
In Linux, commands are ways or instructions through which you can instruct your system to do
some action. Commands are executed in the command line.
Syntax:
Built-in commands are internal commands that are built-in the shell. Built-in commands are
called from the shell and executed directly within the shell itself. You can list all built-in
commands with the help of 'help' and 'compgen -b' command. Some example of built-in
commands are 'pwd', 'help', 'type', 'set', 'unset', etc.
External commands are other than built-in commands. These commands are programs which
have their own binary and located in the filesystem. These are the commands that your system
offer and are totally shell independent. Mostly these commands reside in /bin, /sbin, /usr/sbin.
type command
Linux 'type' command tell us whether a command given to the shell is a built-in or external
command.
Syntax:
1. type <command>
Example:
1. type pwd
2. type cd
3. type man
4. type cat
5. type file
36
Look at above snapshot, commands like 'pwd' and 'cd' are built-in commands while commands
'man', 'cat', and 'file' are external commands.Linux 'type' command also tells whether a
command is aliased or not.
Example:
1. type ls
Look at the above snapshot, 'type' command shows that 'ls' is an aliased command.
type -a
The 'type -a' option tells about all type of command whether it is built-in, external, or aliased.
Some commands are both external and built-in commands. But built-in command will always
takes priority until and unless path of external command is mentioned.
Syntax:
1. type -a <command>
Example:
1. type -a echo
37
Look at the above snapshot, 'echo' command is internal as well as external. To use external
'echo' command, path "/bin/echo" is mentioned.
which
Syntax:
Example:
Look at the above snapshot, except 'cd' command, all other commands are external commands
because bash has displayed their external path.
38
Experiment 9: Shell Scripting – Using variables.
A shell variable is a character string in a shell that stores some value. It could be an integer,
filename, string, or some shell command itself. Basically, it is a pointer to the actual data
stored in memory. We have a few rules that have to be followed while writing variables in
the script (which will be discussed in the article). Overall knowing the shell variable scripting
leads us to write strong and good shell scripts.
1) Accessing variable
Variable data could be accessed by appending the variable name with ‘$’ as follows:
#!/bin/bash
VAR_1="Devil"
VAR_2="OWL"
echo "$VAR_1$VAR_2"
Output:
DevilOWL
39
Experiment 10: Shell Scripting – Input & Output.
Working on Linux applications we have several ways to get information from outside and to
put it inside: command line args, environment variables, files. All of these sources are legal
and good. But it has a finite size. Another way to establish communication is standard
streams: input stream (stdin) used for getting data from outside of the app, output stream
(stdout) to put data outside of the app, and error to put data outside of the app (stderr).
Output:
The script running at the console:
This time we ran 2 commands: “cat stdio1.sh” – to list script body, “./stdio1.sh” to run the
script. “echo pattern” forms the standard output stream that is connected to the standard
input stream of grep. So all of the data comes to grep. grep is an app that writes from input
stream to output stream if it matches the pattern. The first input does not match – no
output expected. The Second-string of the script “echo pattern | grep pattern” has
appropriate input – it has been passed to grep output and displayed at the console next.
40
Experiment 11: Shell Scripting – Data types.
#!/bin/bash
Output:
41
Experiment 12: Shell Scripting – Use of arithmetic operators.
Addition
Code:
Sum=$((10+3))
echo "Sum = $Sum"
Output:
Subtraction Code:
Difference=$((10-3))
echo "Difference = $Difference"
Output:
42