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

Virtual Lab - Operating System-2

OS lab

Uploaded by

yugi s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Virtual Lab - Operating System-2

OS lab

Uploaded by

yugi s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Directorate of Online Education

SRM Institute of Science and Technology

SRM Nagar, Kattankulathur-603203

LAB MANUAL

Course: MCA

SEMESTER
I

SUBJECT TITLE
OPERATING SYSTEM

SUBJECT CODE
MCAO20102

Prepared By
Mr. V. Joseph Raymond
Asst.Professor, NWC
SRM IST

Directorate of Online Education


OBJECTIVES

1. Introduce the key role of an Operating system

2. Insist the Process Management functions of an Operating system

3. Emphasize the importance of Memory Management concepts of an Operating


system

4. Realize the significance of Device Management part of an Operating system

5. Comprehend the need of File Management functions of an Operating system

6. Explore the services offered by the Operating system practically

COURSE OUTCOME

1. Identify the need of an Operating system


2. Know the Process management functions of an Operating system
3. Understand the need of Memory Management functions of an Operating
system
4. Find the significance of Device management role of an Operating system
5. Recognize the essentials of File Management part of an Operating system
6. Gain an insight of Importance of an Operating system through practical

INTRODUCTION ABOUT VIRTUAL LAB

Virtual Lab Content is prepared by Course Coordinator of concern subject to help


the students with their practical understanding and development of programming
skills, and may be used as a base reference during the Practical Assignments. The
model lab programs and List of Exercise Assignment prepared by staff members
will be upload in LMS .Students have to submit Lab Exercise through LMS as

Directorate of Online Education


Assignment Sections as Separate Folder of concern subject . The course
coordinator of concern subject can be evaluated after students submit all program
assignments for end semester sessional examination. The lab Program reporting
style in the prescribed format (Appendix-I) and List of Lab Exercises as
Assignments prescribed format (Appendix-II)

APPENDIX-I
1. Title: Installing Windows in Virtual Machine/Workstation
2. Process Steps/Description
a. Download VMware Player or Workstation recent version.
b. Download Windows any version between Win 7 to Win 11.
c. Install VM ware Player in your host machine.
d. Install Windows as your guest OS using virtualization.
3. Methodology
a. Using Windows Installer
4. Installation Steps
a. Click Create a New Virtual Machine. Alternatively, navigate to Player
> File > New Virtual Machine.
b. Select I will install the operating system later and click next.
c. Ensure that Operating System is set to Microsoft Windows and
Version is set to Windows 10 or Windows 10 x64, depending on
whether it is 32-bit or 64-bit disc image.
d. Click Next.
e. Enter the virtual machine name.

Directorate of Online Education


f. Select the location where you want to store the virtual machine. You
can choose to retain the default location displayed.
g. Click Next.
h. Specify disk capacity for the virtual machine.
i. Click Next.
j. Click Customize Hardware to specify custom hardware specifications
for the virtual machine.
k. Click Close after making the desired changes.
l. Click Finish to save the virtual machine.
5. Sample Output

Directorate of Online Education


6. Result
We have successfully installed Windows using Virtual Machine.

Experiment 2
1. Title: Installing Ubuntu/Linux in Virtual Machine/Workstation
2. Process Steps/Description
a. Download VMware Player or Workstation recent version.
b. Download Ubuntu LTS recent version.
c. Install VM ware Player in your host machine.

Directorate of Online Education


d. Install Linux as your guest OS using virtualization.
3. Methodology
a. Using Windows Installer
4. Installation Steps
a) Open VMware Workstation and click on "New Virtual Machine".
b) Select "Typical (recommended)" and click "Next".
c) Select "Installer disc image (ISO)", click "Browse" to select the Ubuntu ISO
file, click "Open" then "Next".
d) You have to type in "Full name", "User name" that must only consist of
lowercase and numbers then you must enter a password. After you
finished, click "Next".
e) You can type in a different name in "Virtual machine name" or leave as is
and select an appropriate location to store the virtual machine by clicking
on "Browse" that is next to "Location" -- you should place it in a
drive/partition that has at least 5GB of free space. After you selected the
location click "OK" then "Next".
f) In "Maximum disk size" per Ubuntu recommendations you should allocate
at least 5GB -- double is recommended to avoid running out of free space.
g) Select "Store virtual disk as a single file" for optimum performance and click
"Next".
h) Click on "Customize" and go to "Memory" to allocate more RAM -- 1GB
should suffice, but more is always better if you can spare from the installed
RAM.
i) Go to "Processors" and select the "Number of processors" that for a normal
computer is 1 and "Number of cores per processor" that is 1 for single core,
2 for dual core, 4 for quad core and so on -- this is to insure optimum
performance of the virtual machine.
j) Click "Close" then "Finish" to start the Ubuntu install process.

5. Sample Output

Directorate of Online Education


6. Result
We have successfully installed Linux/Ubuntu using Virtual Machine.

Experiment 3

3. Title: Try out Basic Linux Commands


2. Basic Commands
a. pwd — When you first open the terminal, you are in the home directory of
your user. To know which directory you are in, you can use the “pwd” command.
It gives us the absolute path, which means the path that starts from the root. The
root is the base of the Linux file system. It is denoted by a forward slash( / ). The
user directory is usually something like "/home/username".

Directorate of Online Education


b. ls — Use the "ls" command to know what files are in the directory you are in.
You can see all the hidden files by using the command “ls -a”.

c. cd — Use the "cd" command to go to a directory. For example, if you are in the
home folder, and you want to go downloads folder, then you can type in “cd
Downloads”. 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.

d. mkdir & rmdir — Use the mkdir command when you need to create a folder or
a directory. For example, if you want to make a directory called “DIY”, then you
can type “mkdir DIY”. Remember, as told before, if you want to create a directory
named “DIY Hacking”, then you can type “mkdir DIY\ Hacking”. Use rmdir to
delete a directory. But rmdir can only be used to delete an empty directory. To
delete a directory containing files, use rm.

Directorate of Online Education


e. rm - Use the rm command to delete files and directories. Use "rm -r" to delete
just the directory. It deletes both the folder and the files it contains when using
only the rm command.

f. 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”.

g. man & --help — To know more about a command and how to use it, use
the man command. It shows the manual pages of the command. For example,
“man cd” shows the manual pages of the cd command. Typing in the command
name and the argument helps it show which ways the command can be used
(e.g., cd –help).

Directorate of Online Education


h. 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.

i. mv — Use the mv command to move files through the command line. We can
also use the mv command to rename a file. For example, if we want to rename
the file “text” to “new”, we can use “mv text new”. It takes the two arguments,
just like the cp command.

j. locate — The locate command is used to locate a file in a Linux system, just like
the search command in Windows. This command is useful when you don't know
where a file is saved or the actual name of the file. Using the -i argument with the
command helps to ignore the case (it doesn't matter if it is uppercase or
lowercase). So, if you want a file that has the word “hello”, it gives the list of all
the files in your Linux system containing the word "hello" when you type in
“locate -i hello”. If you remember two words, you can separate them using an
asterisk (*). For example, to locate a file containing the words "hello" and "this",
you can use the command “locate -i *hello*this”.
Directorate of Online Education
3. Advance Commands

a. echo — The "echo" command helps us move some data, usually text into a file.
For example, if you want to create a new text file or add to an already made text
file, you just need to type in, “echo hello, my name is alok >> new.txt”. You do
not need to separate the spaces by using the backward slash here, because we
put in two triangular brackets when we finish what we need to write.

b. cat — Use the cat command to display the contents of a file. It is usually used
to easily view programs.

c. nano, vi, jed — nano and vi are already installed text editors in the Linux
command line. The nano command is a good text editor that denotes keywords
with color and can recognize most languages. And vi is simpler than nano. You
can create a new file or modify a file using this editor. For example, if you need to
make a new file named "check.txt", you can create it by using the command
“nano check.txt”. You can save your files after editing by using the sequence
Ctrl+X, then Y (or N for no). In my experience, using nano for HTML editing
doesn't seem as good, because of its color, so I recommend jed text editor. We
will come to installing packages soon.

Directorate of Online Education


d. 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.

e. df — Use the df command to see the available disk space in each of the
partitions in your system. You can just type in df in the command line and you can
see each mounted partition and their used/available space in % and in KBs. If you
want it shown in megabytes, you can use the command “df -m”.

f. du — Use du to know the disk usage of a file in your system. If you want to
know the disk usage for a particular folder or file in Linux, you can type in the
Directorate of Online Education
command df and the name of the folder or file. For example, if you want to know
the disk space used by the documents folder in Linux, you can use the command
“du Documents”. You can also use the command “ls -lah” to view the file sizes of
all the files in a folder.

g. tar — Use tar to work with tarballs (or files compressed in a tarball archive) in
the Linux command line. It has a long list of uses. It can be used to compress and
uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2,etc. It works
on the basis of the arguments given to it. For example, "tar -cvf" for creating
a .tar archive, -xvf to untar a tar archive, -tvf to list the contents of the archive,
etc. Since it is a wide topic, here are some examples of tar commands.

h. zip, unzip — Use zip to compress files into a zip archive, and unzip to extract
files from a zip archive.

i. uname — Use uname to show the information about the system your Linux
distro is running. Using the command “uname -a” prints most of the information
about the system. This prints the kernel release date, version, processor type, etc.

j. 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 sudo command
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).

Directorate of Online Education


k. chmod — Use chmod to make a file executable and to change the permissions
granted to it in Linux. Imagine you have a python code named numbers.py in your
computer. You'll need to run “python numbers.py” every time you need to run it.
Instead of that, when you make it executable, you'll just need to run
“numbers.py” in the terminal to run the file. To make a file executable, you can
use the command “chmod +x numbers.py” in this case. You can use “chmod 755
numbers.py” to give it root permissions or “sudo chmod +x numbers.py” for root
executable. Here is some more information about the chmod command.

l. hostname — Use hostname to know your name in your host or network.


Basically, it displays your hostname and IP address. Just typing “hostname” gives
the output. Typing in “hostname -I” gives you your IP address in your network.

m. ping — Use ping to check your connection to a server. Wikipedia says, "Ping is
a computer network administration software utility used to test the reachability
of a host on an Internet Protocol (IP) network". Simply, when you type in, for
example, “ping google.com”, it checks if it can connect to the server and come
back. It measures this round-trip time and gives you the details about it. The use
of this command for simple users like us is to check your internet connection. If it
pings the Google server (in this case), you can confirm that your internet
connection is active!

Directorate of Online Education


4. Result
We have successfully executed commands in Linux.

Directorate of Online Education


Experiment 4

Title: Write programs using shell scripting covering data types, conditional, and
looping and decision statements.
Description:

A shell script is a computer program designed to be run by the Unix/Linux shell


which could be one of the following:

 The Bourne Shell


 The C Shell
 The Korn Shell
 The GNU Bourne-Again Shell

A shell is a command-line interpreter and typical operations performed by shell


scripts include file manipulation, program execution, and printing text.
1. Basic Shell Scripting
Open editor and type below Code and save as test.sh
#!/bin/sh
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
Output:
$./test.sh
What is your name?
Zara Ali
Hello, Zara Ali
$

Directorate of Online Education


2. Using Arrays
Open editor and type below Code and save as test1.sh
#!/bin/sh
NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"
Output:
$./test1.sh
First Index: Zara
Second Index: Qadir

3. Using Decision Statement

Open editor and type below Code and save as test2.sh


#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]

Directorate of Online Education


then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi
Output:
$./test2.sh
a is less than b
4. Looping Statement
Open editor and type below Code and save as test3.sh
for var in 0 1 2 3 4 5 6 7 8 9
do
echo $var
done
Output:
$./test3.sh
0
1
2
3
4
5
6
7
8
9
5. Result
We have successfully executed commands in Linux.

Directorate of Online Education


Experiment 5
1. Title: Create process using fork () system call and use getpid (), getppid ()
functions along with wait () and exit () using C programming.
2. Description
Both getppid() and getpid() are inbuilt functions defined in unistd.h library.
3. Code
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
int pid;
pid = fork();
if (pid == 0)
{
cout << "\nParent Process id : "
<< getpid() << endl;
wait ();
cout << "\nChild Process with parent id : "
<< getppid() << endl;
exit ();
}
return 0;
}

Directorate of Online Education


4. Output:
Parent Process id of current process: 3849
Child Process with parent id: 3851

5. Result
We have successfully executed fork () system call.

Directorate of Online Education


Experiment 6
1. Title- Write program to implement unidirectional pipe under IPC using C
programming.
2. Description
pipe () function creates a unidirectional pipe for IPC. On success it return
two file descriptors pipefd[0] and pipefd[1]. pipefd[0] is the reading end of
the pipe. So, the process which will receive the data should use this file
descriptor. pipefd[1] is the writing end of the pipe. So, the process that
wants to send the data should use this file descriptor.
3. Code
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
int main()
{
int fd[2],n;
char buffer[100];
pid_t p;
pipe(fd); //creates a unidirectional pipe with two end fd[0] and fd[1]
p=fork();
if(p>0) //parent
{
printf("Parent Passing value to child\n");
write(fd[1],"hello\n",6); //fd[1] is the write end of the pipe

Directorate of Online Education


wait();
}
else // child
{
printf("Child printing received value\n");
n=read(fd[0],buffer,100); //fd[0] is the read end of the pipe
write(1,buffer,n);
}
}
4. Output
$ ./a.out

Parent passing value to child


Child printing received value
5. Result
We have successfully executed pipe () system call.

Directorate of Online Education


APPENDIX-II

LIST OF EXPERIMENTS -ASSIGNMENTS -LMS


Assignment Title of Program
No
1 Installing Windows in Virtual Machine/Workstation.
2 Installing Ubuntu/Linux in Virtual Machine/Workstation.
3 Try out with Linux simple and advance commands.
4 Write programs using shell scripting covering data types,
conditional, and looping and decision statements.
5 Create process using fork () system call and use getpid (), getppid
() functions along with wait () and exit () using C programming.
6 Write program to implement unidirectional pipe under IPC using
C programming.
7 Implement the C program in which the child process calculates
the sum of odd numbers and the parent process calculate the
sum of even numbers up to the number ‘n’.
8 Implement the C program in which main program accepts the
integers to be sorted Main program uses the fork system call to
create a new process called a child process. Parent process sorts
the integers using insertion sort and waits for child process using
wait system call to sort the integers using selection sort.
9 Write a program to print the Child process ID and Parent process
ID in both Child and Parent processes.
10 To understand the overlay concepts and practice how to overlay
the current process to new process in Linux using C.

Directorate of Online Education

You might also like