100% found this document useful (2 votes)
5K views24 pages

Cs3461 Operating System Lab Manual-1-4

Uploaded by

vikashtamila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
5K views24 pages

Cs3461 Operating System Lab Manual-1-4

Uploaded by

vikashtamila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

CS3461 OPERATING SYSTEMS LABORATORY LT P C

0 0 3 1.5

COURSE OBJECTIVES:

✓ To install windows operating systems.


✓ To understand the basics of Unix command and shell programming.
✓ To implement various CPU scheduling algorithms.
✓ To implement Deadlock Avoidance and Deadlock Detection Algorithms
✓ To implement Page Replacement Algorithms
✓ To implement various memory allocation methods.
✓ To be familiar with File Organization and File Allocation Strategies.

LIST OF EXPERIMENTS:

1. Installation of windows operating system

2. Illustrate UNIX commands and Shell Programming

3. Process Management using System Calls : Fork, Exit, Getpid, Wait, Close

4. Write C programs to implement the various CPU Scheduling Algorithms

5. Illustrate the inter process communication strategy

6. Implement mutual exclusion by Semaphore

7. Write C programs to avoid Deadlock using Banker's Algorithm

8. Write a C program to Implement Deadlock Detection Algorithm

9. Write C program to implement Threading

10. Implement the paging Technique using C program

11. Write C programs to implement the following Memory Allocation Methods

a. First Fit b. Worst Fit c. Best Fit

12. Write C programs to implement the various Page Replacement Algorithms

13. Write C programs to Implement the various File Organization Techniques

14. Implement the following File Allocation Strategies using C programs

a. Sequential b. Indexed c. Linked

15. Write C programs for the implementation of various disk scheduling algorithms

16. Install any guest operating system like Linux using VMware.

TOTAL: 45 PERIODS
EX. NO: 1 ) (CASE STUDY): Perform a case study by installing and exploring varioustypes
of operating systems on a physical or logical (virtual) machine. (Linux Installation).
Instructions to Install Ubuntu Linux 12.04 (LTS) along with Windows.

Back Up Your Existing Data!

This is highly recommended that you should take backup of your entire data before start
with the installation process.

Obtaining System Installation Media


Download latest Desktop version of Ubuntu from this link:
http://www.ubuntu.com/download/desktop
Booting the Installation System
There are several ways to boot the installation system. Some of the very popular ways are ,Booting from a
CD ROM, Booting from a USB memory stick, and Booting from TFTP.
Here we will learn how to boot installation system using a CD ROM.
Before booting the installation system, one need to change the boot order and set CD-ROMas first
boot device.
Changing the Boot Order of a Computers
As your computer starts, press the DEL, ESC, F1, F2, F8 or F10 during the initial startup screen.
Depending on the BIOS manufacturer, a menu may appear. However, consult the hardware
documentation for the exact key strokes. In my machine, its DEL key as shown in following screen-

shot.
2. Find the Boot option in the setup utility. Its location depends on your BIOS.
Select the Boot option from the menu, you can now see the options Hard Drive, CD-ROM
Drive, Removable Devices Disk etc.
3. Change the boot sequence setting so that the CD-ROM is first. See the list of “Item Specific
Help” in right side of the window and find keys which is used to toggle to change the boot
sequence.

4. Insert the Ubuntu Disk in CD/DVD drive.


5. Save your changes. Instructions on the screen tell you how to save the changes on
yourcomputer. The computer will restart with the changed settings.
Machine should boot from CD ROM, Wait for the CD to load...

In a few minutes installation wizard will be started. Select your language and click the
"Install Ubuntu" button to continue...

Optionally, you can choose to download updates while installing and/or install third party
software, such as MP3 support. Be aware, though, that if you select those options, the entire
installation process will be longer!
Since we are going to create partitions manually, select Something else, then click Continue.
Keep in mind that even if you do not want to create partitions manually, it is better to select the same
option as indicated here. This would insure that the installer will not overwrite yourWindows , which
will destroy your data. The assumption here is that sdb will be used just for Ubuntu 12.04, and that
there are no valuable data on it.
Where are you? Select your location and Click the "Continue" button.

Keyboard layout
Select your keyboard layout and UK (English) and Click on “Continue” button.

Who are you?


Fill in the fields with your real name, the name of the computer (automatically generated,
but can be overwritten), username, and the password.
Also at this step, there's an option called "Log in automatically." If you check it, you will
automatically be logged in to the Ubuntu desktop without giving the password.
Option "Encrypt my home folder," will encrypt your home folder. Click on the "Continue"
button to continue...
Now Ubuntu 12.04 LTS (Precise Pangolin) operating system will be installed.

It will take approximately 10-12 minutes (depending on computer's speed), a pop-up window
will appear, notifying you that the installation is complete, and you'll need to restart thecomputer in
order to use the newly installed Ubuntu operating system. Click the "Restart Now" button.
Please remove the CD and press the "Enter" key to reboot. The computer will be restarted. In
a few seconds, you should see Windows 7′s boot menu with two entires listed – Windows 7 and
Ubuntu 12.04 (LTS).
Then you may choose to boot into Windows 7 or Ubuntu 12.04 using the UP/Down arrow key.

Please select Ubuntu 12.04 (LTS) and press Enter to boot the machine in Ubuntu 12.04
Linux.
Here you can see the users on the machine, Click on the user name and enter the
passwordand press Enter key to login.

We have successfully install and login to Ubuntu 12.04 LTS.


EX. NO: 2 ) SHELL PROGRAMMIG
i BASIC ARITHMETIC OPERATION USIG SHELL PROGRAMMIG

AIM: To write a shell program to solve arithmetic operation.

ALGORITHM :

Step 1 : Include the necessary header files.


Step 2 : get the input
Step 3 : perform the arithmetic calculation.
Step 4 : print the result.
Step 5 :stop the exeution.
PROGRAM CODING:

#!/bin/bash
echo "enter the a vale"
read a
echo "enter b value"
read b
c=`expr $a + $b`
echo "sum:"$c
c=`expr $a - $b`
echo "sub:"$c
c=`expr $a \* $b`
echo "mul:"$c
c=`expr $a / $b`
echo "div:"$c

OUTPUT:

[2mecse25@rhes3linux ~]$ sh pg2.sh


Enter the a vale
10
Enter b value 50
sum:60 sub:-40 mul:500 div:0

RESULT:
Thus the program was executed successfully
EX. NO: 2 ) ii NUMBER CHECKIG USIG SHELL PROGRAM

AIM: To write a shell program to check whether the number is odd or even.

ALGORITHM :

Step 1 : Include the necessary header files. Step 2 : get the input
Step 3 : perform the division by 2. Step 4 : print the result.
Step 5 :stop the execution.

PROGRAM CODING:
#!/bin/bash
num="1 2 3 4 5 6 7 8"
for n in $num
do
q=`expr $n % 2`
if [ $q -eq 0 ]
then
echo "even no"
continue
fi
echo "odd no"
done

OUTPUT:
[2mecse25@rhes3linux ~]$ sh pg2.sh
odd no
even no
odd no
even no
odd no
even no
odd no
even no

RESULT:
Thus the program was executed successfully
EX. NO: 2 ) iii MULTIPLICATION TABLE USIG SHELL PROGRAM

AIM: To write a shell program to check whether the number is odd or even.

ALGORITHM ::
Step 1 : Include the necessary header files.
Step 2 : get the input
Step 3 : perform the multiplication .
Step 4 : print the result.
Step 5 :stop the execution.

PROGRAM CODING:
#!/bin/bash
echo " which table you want"read n
for((i=1;i<10;i++))do
echo $i "*" $n "=" `expr $i \* $n`
done

OUTPUT:

[2mecse25@rhes3linux ~]$ sh pg2.sh


which table you want
5
1*5=5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45

RESULT:
Thus the program was executed successfully
EX. NO: 2 ) iv USING WHILE LOOP IN SHELL PROGRAM

AIM: To write a shell program to print the number from 1 to 10 using while loop.

ALGORITHM :
Step 1 : Include the necessary header files.
Step 2 : Define the buffer size as 1024.
Step 3 : Get the file name which has been created already.
Step 4 : Open the file in read mode.
Step 5 :.Read the contents of the file and store it in the buffer.
Step 6 : Print the contents stored in the buffer.
Step 7 : Close the file.

PROGRAM CODING:
#!/bin/bash
a=1
while [ $a -lt 11 ]
do
echo "$a"
a=`expr $a + 1`
done

OUTPUT:
[2mecse25@rhes3linux ~]$ sh pg2.sh 1
2
3
4
5
6
7
8
9
10
RESULT:
Thus the program was executed successfully.
EX. NO: 2 ) vi SIMPLE FUNCTION IN SHELL PROGRAMING

AIM: To write a shell program to add a two number using function .

ALGORITHM :
Step 1 : Include the necessary header files.
Step 2 : Define the buffer size as 1024.
Step 3 : Get the file name which has been created already.
Step 4 : Open the file in read mode.
Step 5 :.Read the contents of the file and store it in the buffer.
Step 6 : Print the contents stored in the buffer.
Step 7 : Close the file.

PROGRAM CODING:
#!/bin/bash
add()
{
c=`expr $1 + $2`
echo "addition = $c"
}
add 5 10

OUTPUT:
[2mecse25@rhes3linux ~]$ sh pg2.sh
addition = 15

RESULT:
Thus the program was executed successfully
EX. NO: 2 ) vii SWITCH STATEMENT IN SHELL PROGRAMING
AIM: To write a shell program to add a two number using function .
ALGORITHM :
Step 1 : Include the necessary header files.
Step 2 : Define the buffer size as 1024.
Step 3 : Get the file name which has been created already.
Step 4 : Open the file in read mode.
Step 5 :.Read the contents of the file and store it in the buffer.
Step 6 : Print the contents stored in the buffer.
Step 7 : Close the file.
PROGRAM CODING
#!/bin/bash
ch='y'
while [ $ch = 'y ' ]
do
echo "enter your choice"
echo "1 no of user loged on"
echo "2 print calender"
echo "3 print date"
read d
case $d in
1) who | wc -l;;
2) cal 20;;
3) date;;
*) break;; esac
echo "do you wish to continue (y/n)"
read ch
OUTPUT:
[2mecse25@rhes3linux ~]$ sh case2.sh
enter your choice
1 no of user loged on
2 print calender
3 print date
Thu Apr 4 11:18:20 IST 2013
do you wish to continue (y/n) n
RESULT:
Thus the program was executed successfully
EX. NO: 3 ) a)PROCESS MANAGEMENT USING SYSTEM
CALLS:FORK,EXIT,GETPID,WAIT,CLOSE
AIM: To write the program for system calls of unix Operating
Systems(Opendir,Readdir,closedir,etc..)
ALGORITHM :
Step 1: Start the program.
Step 2: Declare the variables pid and child id.
Step 3: Get the child id value using system call fork().
Step 4: If child id value is greater than zero then print as “i am in the parent process”.

Step 5: If child id! = 0 then using getpid() system call get the process id.
Step 6: Print “i am in the parent process” and print the process id.
Step 7: If child id! = 0 then using getppid() system call get the parent process id.

Step 8: Print “i am in the parent process” and print the parent process id.
Step 9: Else If child id value is less than zero then print as “i am in the child process”.
Step 10: If child id! = 0 then using getpid() system call get the process id.
Step 11: Print “i am in the child process” and print the process id.
Step 12: If child id! = 0 then using getppid() system call get the parent process id.

Step 13: Print “i am in the child process” and print the parent process id.
Step 14: Stop the program.

PROGRAM CODING

#include<stdio.h>
#include<dirent.h>
struct dirent*dptr;
int main(int argc,char *argv[])
{
char buff[100];
DIR *dirp;
printf("\n\n Enter the Directory name");
scanf("%s",buff);
if((dirp=opendir(buff))==NULL)
{
printf("the given directory does not exist");
exit(1);
}
while(dptr=readdir(dirp))
{
printf("%s\n",dptr->d_name);
}
closedir(dirp);
}

OUTPUT:

ENTER THE DIRECTORY NAME:UNIT


CHAP1.C
CHAP2.C
RESULT:
Thus the program was executed successfully
AIM: To write the program to implement the system calls of Operating System(Fork, sGetpid,Exit,etc)

ALGORITHM :
Step 1 : Declare the variables pid , parent pid , child id and grand chil id.
Step 2 : Get the child id value using system call fork().
Step 3 : If child id value is less than zero then print as “error at fork() child”.
Step 4 : If child id !=0 then using getpid() system call get the process id.
Step 5 : Print “I am parent” and print the process id.
Step 6 : Get the grand child id value using system call fork().
Step 7 : If the grand child id value is less than zero then print as “error at fork() grandchild”.
Step 8 : If the grand child id !=0 then using getpid system call get the process id.
Step 9 : Assign the value of pid to my pid.
Step 10 : Print “I am child” and print the value of my pid.
Step 11 : Get my parent pid value using system call getppid().
Step 12 : Print “My parent‟s process id” and its value.
Step 13 : Else print “I am the grand child”.
Step 14 : Get the grand child‟s process id using getpid() and print it as “my process id”.
Step 15 : Get the grand child‟s parent process id using getppid() and print it as “my parent‟sprocess id
PROGRAM CODING
#include<stdio.h>
#include<unistd.h>
main()
{
int pid,pid1,pid2;
pid=fork();
if(pid==-1)
{
printf("error in process creation\n");
exit(1);
}
if(pid!=0)
{
pid1=getpid();
printf("\n the parent process ID is:%d\n",pid1);
}
else
{
pid2=getpid();
printf("\n the child process ID is:%d\n",pid2);
}
}
OUTPUT:
the child process ID is:5394

the parent process ID is:5393

RESULT:
Thus the program was executed successfully
EX. NO: 4) implement the various CPU Scheduling Algorithms

A. FIRST COME FIRST SERVE:

AIM: To write a c program to simulate the CPU scheduling algorithm First Come First
Serve (FCFS)

ALGORITHM :
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the burst time
Step 4: Setthe waiting of the first process as ‗0„and its burst time as its turnaround time
Step 5: 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)
Step 6: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process

PROGRAM CODING
// First Come First Serve ( FCFS Program in C)
#include<stdio.h>
#include<conio.h>
main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg;
clrscr();
printf("\nEnter the number of processes -- ");
scanf("%d", &n); for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]); printf("\nAverage Waiting Time –%f",
wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
getch();
}

INPUT:
Enter the number of processes --3
Enter Burst Time for Process 0 --24
Enter Burst Time for Process 1 --3
Enter Burst Time for Process 2 --3

OUTPUT:
P BURS WAITIN TURNAROUN
R T GTIME DTIME
O TIME
C
E
SS
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time-- 17.000000
Average Turnaround Time -- 27.000000

RESULT:
Thus the program was executed successfully

B. SHORTEST JOB FIRST:

AIM: To write a program to stimulate the CPU scheduling algorithm Shortest job first (Non-
Preemption)

ALGORITHM :
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest
to highest burst time.
Step 5: Set the waiting time of the first process as ‗0„ and its turnaround time as its burst
time.Step 6: Sort the processes names based on their Burt time
Step 7: For each process in the ready queue, calculate
a) Waiting time(n)= waiting time (n-1) + Burst time (n-1)
b) Turnaround time (n)= waiting time(n)+Burst time(n)
Step 8: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number ofprocess
Step 9: Stop the process
PROGRAM CODING
#include<stdio.h
>
#include<conio.h
>main()
{
int p[20], bt[20], wt[20], tat[20], i, k, n, temp;
float wtavg, tatavg;
clrscr();
printf("\nEnter the number of processes -- ");
scanf("%d", &n);for(i=0;i<n;i++)
{
p[i]=i;
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for(i=0;i<n;i++) for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i]; bt[i]=bt[k]; bt[k]=temp;
temp=p[i]; p[i]=p[k]; p[k]=temp;
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0]; for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i]; wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\n\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
getch();
}
INPUT:

Enter the number of processes –4


Enter Burst Time for Process 0 –6
Enter Burst Time for Process 1 --8
Enter Burst Time for Process 2 --7
Enter Burst Time for Process 3 –3

OUTPUT:

PRO BURS WAITIN TURNAROUND


CES T GTIME TIME
S TIME
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
Average Waiting Time --7.000000
Average Turnaround Time --
13.000000

RESULT:
Thus the program was executed successfully

C. ROUND ROBIN:

AIM: To simulate the CPU scheduling algorithm round-robin.

ALGORITHM :
Step 1: Start the process
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 time process (n)/time slice
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 timeof 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 process(n)+ thetime
difference in getting CPU from process(n).
Step 7: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number ofprocess
Step 8: Stop the process

PROGRAM CODING
#include<stdio.h
>main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
clrscr();
printf("Enter the no of processes -- ");
scanf("%d",&n);for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0]; for(i=1;i<n;i++)
if(max<bu[i]) max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];
}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is --%f ",awt/n);
printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);
getch();
}

INPUT:

Enter the no of processes – 3


Enter Burst Time for process 1 –
24Enter Burst Time for process 2 -
- 3 Enter Burst Time for process 3
– 3 Enter the size of time slice – 3

OUTPUT:

PROCESS BURST TIME WAITING TIME TURNAROUNDTIM


E
1 24 6 30
2 3 4 7
3 3 7 10
The Average Turnaround time is – 15.666667
The Average Waiting time is ---------- 5.666667

RESULT:
Thus the program was executed successfully

You might also like