0% found this document useful (0 votes)
589 views98 pages

Os Lab Manual

ANNA UNIVERSITY LAB MANUAL

Uploaded by

Saravana Kumar
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
0% found this document useful (0 votes)
589 views98 pages

Os Lab Manual

ANNA UNIVERSITY LAB MANUAL

Uploaded by

Saravana Kumar
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/ 98

Ex.

No: 1 INSTALLATION OF WINDOWS OPERATING SYSTEM


Date:

Aim:
To install the windows operating system.
Procedure:
1. Installation of windows Operating System.
WINDOWS INSTALLTION REPORT:
HOW TO MAKE USB BOOTABLE USING RUFUS
Make sure that you are using Usb Drive that is Atleast 4gb For The 32-Bit- Version and
8gb for the 64-Bit Version.
Rufus is one of several programs that allow you to create an "ISO image" on a USB
drive. To create a bootable USB using Rufus, all we need is:
 ISO of our choice, e.g. Windows 10
 Any version of Rufus
 A spare USB drive (an 8GB USB should be plenty for Windows 10 but make sure
you have one that's large enough for the ISO you're using)
DOWNLOADING WINDOWS ISO
STEP 1: Navigate to http://www.microsoft.com/en-us/software-download/windows 10
site & choose the Download tool now button.

STEP 2: (a) Run the media Creation Tool.exe. to upgrade or download Windows 10

1
STEP 3: At the next screen, choose Create Installation media for another PC & press
Next.
Important Notes
1. In order to perform a clean installation of Windows 10, you must own a valid
Windows 10 product key to activate Windows.
2. If you bought a pre-installed Windows 10 computer (on which the OS v S was pre-
installed from the computer manufacturer), then the product key is stored in BIOS and it
will be retrieved automatically (from BIOS) during Windows installation.
3. If you're currently running Windows 8.1 or Windows 7 SP1 (already activated), and
you want to upgrade your computer to Windows 10 select "Upgrade this PC now" at the
next screen & then follow the onscreen instruction to upgrade your OS to Windows 10.

2
STEP 4: Choose the Windows 10 Edition that you want to download and click Next.
Important Notes
1. If you want to install Windows 10 on the current PC, leave the Use the recommended
options for this PC box checked. At this case the Media Creation Tool will create a
Windows 10 installation disk with the same language edition, and architecture
as the current PC.
2. If you want to install Windows 10 on a different PC, language, edition. architecture,
uncheck the Use the recommended options for this PC box and then choose the Windows
10 language, edition, and architecture that you want to download. **
> For Windows 10 as selected edition. This option can install both the Home and Pro
edition (according to your product key).

3
STEP 5: Make sure that you have selected the correct installation media to create and
press OK.

STEP 6: At the next screen choose the option ISO file and click Next.
Important Notes
1. By selecting ISO file, you will be able to store Windows 10 on your computer for later
usage or to burn a bootable Windows 10 DVD after Windows 10 ISO download is
completed.
2. If you want to create a Windows 10 USB installation media select USB flash drive and
then follow the instructions on this post: How to create a bootable Windows 10 USB
disk.

4
v

STEP 7: Choose the destination location (where the ISO file will be saved/stored) &
press Save

STEP 8: When the Windows 10 ISO download is completed then:


1. Click Open DVD burner and place a blank DVD disk on the DVRW tray in order to
create immediately a bootable Windows 10 DVD installation/repair disk, or
2. Click Finish.

5
Result:
Thus the installation of windows operating system is completed successfully.

6
Ex. No:2 (a) BASICS OF UNIX COMMANDS
Date:

AIM:
To study and execute the commands in unix.
COMMAND:
1. Date Command:
This command is used to display the current data and time.
Syntax:
$date
$date +%ch
Options:
a = Abbrevated weekday.
A = Full weekday.
b= Abbrevated month.
B = Full month.
C = Current day and time.
C = Display the century as a decimal number.
D = Day of the month.
D = Day in ,,mm/dd/yy? formal
h = Abbrevated month day.
H= Display the hour.
L= Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T= HH: MM: SS format

7
u = Week of the year.
y = Display the year in 2 digit
Y = Display the full year.
Z= Time zone.
To change the format:
Syntax:
$date "4H-%M-%5"
2. Calender Command:
This command is used to display the calendar of the year or the particular month
of calendar year.
Syntax :
a. $cal <year>
b. $cal <month> <year>
Here the first syntax gives the entire calendar for given year & the second Syntaxgives the
calendar of reserved month of that year.
3. Echo Command:
This command is used to print the arguments on the screen.
Syntax: $echo <text>
Multi line echo command:
To have the output in the same line, the following commands can be used. Syntax: $echo
<text\>text
To have the output in different line, the following command can be used.
Syntax: $echo ?text
>line 2
>line3?
4. 'who' Command:
It is used to display who are the users connected to our computer currently.
Syntax : $who-option's
Options:-

8
H-Display the output with headers.
b-Display the last booting date or time or when the system was lastely rebooted.
5. who am I Command:
Display the details of the current working directory.
Syntax : $who am i
6. 'tty' Command:
It will display the terminal name.
Syntax : $ity
7. Binary' Calculator Command:
It will change the '$' mode and in the new mode, arithmetic operations such as + 7. %, n. sqrt(),
length(),=, etc can be performed. This command is used to go to the binary calculus mode.
Syntax:
$be operations
^d
$
1 base - inputbase
0 base outputhase are used for base conversions.
Base: Decimal = 1 Binary = 2 Octal 8 Hexa = 16
8. 'CLEAR' Command:
It is used to clear the screen.
Syntax: $clear
9. MAN' Command:
It helps us to know about the particular command and its options & working. It i
like 'help' command in windows.
Syntax: $man <command name>
10. MANIPULATION Command:
It is used to manipulate the screen.
Syntax: Stput <argument>
Arguments:

9
1. Clear to clear the screen. -
2. Longname-Display the complete name of the terminal.
3. SMSO background become white and foreground become black color.
4. rmso background become black and foreground becomes white color.
11. LIST Command:
It is used to list all the contents in the current working directory.
Syntax: $ ls-options <arguments>
If the command does not contain any argument means it is working in the Current
directory.
Options:
a- used to list all the files including the hidden files.
c-list all the files columnwise. d- list all the directories.
m- list the files separated by commas.
p- list files include " to all the directories. T-list the files in reverse alphabetical
order.
f-list the files based on the list modification date.
x-list in column wise sorted order.
DIRECTORY RELATED COMMANDS:
1.Present Working Directory Command:
To print the complete path of the current working directory
Syntax: $pwd
2.MKDIR Command:
To create or make a new directory in a current directory.
Syntax: $mkdir <directory name>
3.CD Command:
To change or move the directory to the mentioned directory.
Syntax: $cd <directory name.
4.RMDIR Command:
To remove a directory in the current directory & not the current
10
Syntax: $rmdir <directory name>
FILE RELATED COMMANDS:
1. CREATE A FILE:
To create a new file in the current directory we use CAT command.
Syntax: $cat > filename
The > symbol is redirectory we use cat command.
2. DISPLAY A FILE:
To display the content of file mentioned we use CAT command without ">" operator.
Syntax: $cat filename
3. COPYING CONTENTS:
To copy the content of one file with another. If file doesnot exist, a new file in created and if
the file exists with some data then it is overwritten.
Syntax:
$cat <filename source>>> <destination filename>
$cat <source filename>>> <destination filename> it is avoid overwriting.
Options:-
-n content of file with numbers included with blank lines.
Syntax:
$cat ?n <filename>
4. SORTING A FILE:
To sort the contents in alphabetical order in reverse order.
Syntax:
$sort <filename>
5. COPYING CONTENTS FROM ONE FILE TO ANOTHER:
To copy the contents from source to destination file. So that both contents are same.
Syntax:
$ep <source filename> <destination filename>
6. MOVE Command:

11
To completely move the contents from source file to destination file and to removethe source
file.
Syntax:
$ mv <source filename> <destination filename>
7. REMOVE Command:
To permanently remove the file we use this command.
Syntax:
$ em <filename>
8. WORD Command:
To list the content count of no of lines, words, characters.
Syntax:
$ we <filename>
Options:
-c- to display no of characters.
-l- to display only the lines.
-w-to display the no of words.
9. LINE PRINTER:
To print the line through the printer, we use lp command.
Syntax:
$ lp <filename>
10. PAGE Command:
This command is used to display the contents of the file page wise & next page can be
viewed by pressing the enter key.
Syntax:
$ pg <filename>
11. FILTERS AND PIPES
HEAD: It is used to display the top ten lines of file.
Syntax: $head<filename>

12
TAIL: This command is used to display the last ten lines of file.
Syntax: $tail<filename>
PAGE: This command shows the page by page a screen full of information is displayed
after which the page command displays a prompt and passes for the user to strike the
enter key to continue scrolling.
Syntax: $is ?ap
MORE: It also displays the file page by page. To continue scrolling with more
command. press the space bar key.
Syntax: $more<filename>
GREP: This command is used to search and print the specified patterns from the file.
Syntax: $grep [option] pattern <filename>
SORT: This command is used to sort the data in some order.
Syntax: $sort<filename>
PIPE: It is a mechanism by which the output of one command can be channeled into the
input of another command.
Syntax: $who |wc -l
TR: The tr filter is used to translate one set of characters from the standard inputs to
another.
Syntax: $tr "[a-z]" "[A-Z]"
COMMUNICATION THROUGH UNIX COMMANDS
1. MESG
Description: The message command is used to give permission to other users to send message to
your terminal.
Syntax: $mesg y

2. Command: WRITE
Description: This command is used to communicate with other users, who are logged in at the
same time.
Syntax: $write <user name>
3. Command: WALL

13
Description: This command sends message to all users those who are logged in using the unix
server.
Syntax: $wall <message>
4. Command: MAIL
Description: It refers to textual information, which can be transferred from one user to another
Syntax: $mail <user name>
5. Command: REPLY
Description: It is used to send reply to specified user.
Syntax: $reply<user name>

Result:
Thus the basic unix commands has been studied and executed successfully.
14
Ex. No:2 (b) SHELL PROGRAMMING
Date:

Aim:
To wite the C program to implement Shell programming.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

(i) CONCATENATION OF TWO STRINGS


Program:
echo "enter the first string"
read strl
echo "enter the second string"
read str2
echo "the concatenated string is" $strl $str2 3 0 MURIX
Sample I/P:
Enter first string: Hello
Enter first string: World
Sample O/P:
The concatenated string is Hello World.
(ii) COMPARISON OF TWO STRINGS
Program:
echo "enter the first string"

15
read strl
echo "enter the second string"
read str2
if [ $strl = $str2 |
then
echo "strings are equal"
else
echo "strings are unequal"
fi
Sample I/P:1
Enter first string: hai
Enter second string: hai
Sample O/P:1
The two strings are equal
Sample I/P:2
Enter first string: hai
Enter second string: cse
Sample O/P:2
The two strings are not equal
(iii) MAXIMUM OF THREE NUMBERS
Program:
echo "enter A"
read a
echo "enter B"
read b
echo "enter C"
read c
if [ $a -gt Sb-a $a -gt $c 1

16
then
echo "A is greater"
elif [ $b-gt Sa -a Sb -gt Sc ]
then
echo "B is greater"
else
echo "C is greater"
fi
Sample I/P:
Enter A:23
Enter B:45
Enter C:67
Sample O/P:
C is greater
(iv) FIBONACCI SERIES
Program:
echo enter the number
read n
a=-1
b=1
i=0
while [ $i ?le $n]
do
t='expr $a + $b'
echo $t
a=$b
b=$t
i='expr $i + 1

17
done
Sample I/P :
Enter the no:
Sample O/P: 0
1
1
2
3
5
(v) ARITHMETIC OPERATIONS USING CASE
Program
echo 1.Addition
echo 2.Subraction
echo 3.Multiplication
echo 4.Division
echo enter your choice
read a
echo enter the value of b
read b
echo enter the value of c
read c
echo b is $b c is Sc
case Sa in
1)d='expr Sb + Se
echo the sum is Sd
2)d='expr $b Sc
echo the difference is $d
3)d='expr $b \ $c

18
echo the product is $d
4)d='expr $b / Sc
echo the quotient is $d
esac
Sample I/P :
1.Addition
2.Subraction
3. Multiplication
4.Division
Enter your choice: 1
Enter the value of b:3
Enter the value of c:4
b is 3 c is 4
the sum is 7
Sample O/P:
b is 3 c is 4
the sum is 7

Result:
Thus the program was executed and verified the output successfully.

19
Ex. No:3 PROCESS MANAGEMENT USING SYSTEM
Date: CALLS: fork, exit, getpid, WAIT CLOSE

Aim:
To wite the C program to implement Process management using system calls: fork, exit, getpid,
wait close.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

(a) fork
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h> #include<sys/types.h>
int main(int argc, char *argv)
{
pid pid:
pid = fork();
if(pid==0)
{
printf("It is the child process and pid is %d\n".getpid()):
exit(0);
}
20
else if(pid > 0)
{
printf("It is the parent process and pid is %d\n".getpid());
}
else
{
printf("Error while forking\n");
exit(EXIT FAILURE);
}
return 0;
}

(b) wait
#include<stdio.h> // printf()
#include<stdlib.h> // exit()
#include <sys/types.h> // pid_
#include<sys/wait.h> // wait()
#include <unistd.h> // fork
int main(int argc, char **argv)
{
pid i pid:
pid = fork();
if(pid==0)
{
printf("It is the child process and pid is %d".getpid()):
int i=0;
for(i=0;i<8;i++)
{

21
printf("%d\n",i);
}
exit(0);
}
else if(pid > 0)
{
printf("It is the parent process and pid is %d\n",getpid()):
int status;
wait(& status);
printf("Child is reaped\n");
}
else
{
printf("Error in forking..\n");
exit(EXIT_FAILURE);
}
return 0;
}
(c) GETPID()
#include <stdio.h>
#include <sys/ types.h>
int main(void)
{
if((fork())<0)
{
printf("process id is not obtained\n");
exit(1);
}

22
Else
{
int pid_t= getpid();
printf("Process id is %d\n".pid_1):;
printf("process id is greater than 0. It is obtained.\n");
sleep(1);
exit(0);
}
Return 0;
}

(d) exit
#include <stdio.h>
#include <stdlib.h>
int main ()
{
// declaration of the variables
int i, num;
printf ("Enter the last number: ");
scanf("%d", &num);
for (i = 1; i<num; i++)
{
// use if statement to check the condition
if (i == 6)
/* use exit () statement with passing 0 argument to show termination of the program without any
error message. */
23
exit(0);
else
printf("\n Number is %d", i);
}
return 0;
}

(e) close()
#include <stdlib.h>
#include <fcntl.h>
int main()
{
size_t filedesc = open("testfile.txt", O_WRONLY | O_CREAT):
if(filedesc < 0)
return 1;
if(close(filedesc) < 0)
return 1:
return 0;
}

Result:
Thus the program was executed and verified the output successfully.

24
Ex.No:4(a) IMPLEMENTATION OF FCFS SCHEDULING
Date:
Aim:
To wite the C program to perform the implementation of FCFS Scheduling .
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<stdio.h>
main()
{
int n,a[10],b[10].[10],w[10].g[10].i.m;
floatatt=0,awt=0;
for(i=0;i<10;i++)
{
a[i]=0; b[i]=0; w[i]=0; g[i]=0;

}
printf("enter the number of process");
scanf("%d", &n);
printf("enter the burst times");
for(i=0;i<n;i++)
scanf("%d", &b[i]);
printf("\nenter the arrival times");

25
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i];
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i]:
t[i]=g[i+1]-a[i]:
awt=awr+w[i];
att=att+t[i]:
}awt #awt/n:
att=att/n:
printf("\\process waiting time turnarround time\n");
for(i=0;i<n;i++)
{
print pdd\\%d\n¨‚¿‚w[i],[
}
printf "the average waiting time is %n":
printf("the average turn around time is %\n",att);
OUTPUT:

enter the number of process 4


enter the burst times
4 9 8 3
enter the arrival times
0 2 4 3

26
Process waiting time turn arround time
Po 0 4
P1 2 11
P2 9 17
P3 18 21

the average waiting time is 7.250000


the average turn around time is 13.250000

Result:
Thus the program was executed and verified the output successfully.

27
Ex.No:4(b) IMPLEMENTATION OF SJF SCHEDULING
Date:
Aim:
To wite the C program to perform the implementation of SJF Scheduling.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include<stdio.h>
int main()
{
int nj,temp,templ,temp2,pr[10],b[10],t[10],w[10],p[10],i;
floatatt=0,awt 0:
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
printf("enter the number of process");
scanf("%d", &n);
printf("enter the burst times");
for(i=0;i<n;i++)
}
Scanf(“%d”,&b[i]);

28
P[i]=I;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(b[i]>bljll
{
temp=b[i];
templ=p[i];
b[i]=b[i];
plil-plil;
b[j]=temp;
p[i]=temp1;
}
}
}
w[0]=0;
for(i=0;i<n;i++)
w[i+1]=w[i]+b[i];
for(i=0;i<n;i++)
{
t[i]=w[i]+b[i];
awt=awt+w[i];
att=att+t[i]:
}
awt=awt/n;
att=att/n;

29
printf("\t process \t waiting time \ turn around time \n");
for(i=0;i<n;i++)

printf("\t p[%d] \t%d \t\t%d\n",p[i],w[i],t[i]);


printf("the average waitingtimeis %f\n",awt);
printf("the average turn around time is %f\n",att);
return 1;
}

OUTPUT:

enter the number of process 5


enter the burst times
2 4 5 6 8

Process waiting time turn arround time


P[0] 0 2
P[1] 2 6
P[2] 6 11
p[3] 11 17
P[4] 17 25

the average waitingtime is 7.200000


the average turn around time is 12.200000

Result:
Thus the program was executed and verified the output successfully.

30
Ex.No:4(c) IMPLEMENTATION OF PRIORITY SCHEDULING
Date:
Aim:
To wite the C program to perform the implementation of Priority Scheduling.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include<stdio.h>
int main()
{
int bi[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; printf("Enter Total
Number of Process:"):
scanf("%d", &n);
printf("Enter Burst Time and Priority");
for(i=0;i<n;i++)
{
printf("P[%d\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1;
}
31
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}

32
avg_wt=total/n;
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i]:
printf("\nP[%d %d\\t %d\\\t%d",p[i].bt[i],wt[i].tat[i]);
}
avg_tat=total/n;
printf("\n\nAverage Waiting Time=%d",avg_wt);
printf("\nAverage Turnaround Time=%d\n",avg_tat);
return 0;
}

OUTPUT:
Enter Total Number of Process:4 Enter Burst Time and Priority
P[1]-
Burst Time:6
Priority:3
P[2]
Burst Time:2
Priority:2
P[3]
Burst Time:14
Priority:1
P[4]

33
Burst Time:6
Priority:4

process Burst Time waiting time turn arround time


P[3] 14 0 14
P[2] 2 14 16
P[1] 6 16 22
P[4] 6 22 28

Average Waiting Time=13


Average Turnaround Time=20

Result:
Thus the program was executed and verified the output successfully.

34
Ex.No:4(d) IMPLEMENTATION OF ROUND ROBIN SCHEDULING
Date:
Aim:
To wite the C program to perform the implementation of Round Robin Scheduling.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include <stdio.h>
int main()
{
Intcount,j,n,time,remain flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at/101,bi[10],ri[10];
printf "Enter Total Process: ");
scanf("%d", &n);
remain=n;
for(count=0;count<n; count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d":"count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];

35
}
printf "Enter Time Quantum:N");
scanf("%d", &time_quantum);
printf("\n\nProcess\t| TurnaroundTime| Waiting Times\n\n”);
for(time=0,count=0; remain!=0;)
{
If(rt[count]<=time_quantum&&rt[count]>0)
{
time+=rt/count];
rt[count]=0;
flag=1;
}
else if(r[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
If(rt[count]==0 && flag==1)
{
remain--;
printf("%d %d %d]" coconut time-at[count],time-at[count]-br[count]);
wait_time+=time-at[count]-bi[count];
turnaround time+time-at[count]:
flag=0;
}
If( count==n-1)
count=0;
else if(at[count+1]<=time)

36
count++
else
count=0;
}
printf "\nAverage Waiting Time= %f\n",wait time 1.0/n):
printf("Avg Turnaround Time=%f”turnaround_time*1.0/n);
return 0;
}

OUTPUT:
Enter Total Process: 4
Enter Arrival Time and Burst Time for Process Process Number 1:0
9
Enter Arrival Time and Burst Time for Process Process Number 2:1
5
Enter Arrival Time and Burst Time for Process Process Number 3:2
3
Enter Arrival Time and Burst Time for Process Process Number 4:3
4
Enter Time Quantum:5

Process Turn Arround Time Waiting Time


P[2] 9 4
P[3] 11 8
P[4] 14 10
P[1] 21 12

37
Average Waiting Time= 8.500000
Avg Turnaround Time = 13.750000

Result:
Thus the program was executed and verified the output successfully.

38
Ex.No:5 INTER PROCESS COMMUNICATION USING SHARED MEMORY
Date:
Aim:
To wite the C program to perform Inter Process Communication using Shared memory .
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include<stdio.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<sys/ipc.h>
int main()
{
int child,shmid,i;
char*shmptr;
child-fork();
if(!child)
{
shmid-shmget(2041,32,1PC_CREAT10666);
shmptr=shmat(shmid,0,0);
printf(" Parent writing\n")`;
for(i=0;i<10;i++)

39
{
shmptr[i]='a'+i;
putchar(shmptr[i]):
}
printf("\n %s", shmptr);
wait(NULL);
}
else
{
shmid=shmger(2041,32,0666);
shmptr=shmat(shmid,0,0);
printf("\n Child is reading\n");
for(i=0;i<10;i++)
putchar(shmptr[i]);
shmdt(NULL);
shmctl(shmid,IPC_RMID,NULL);
}
return 0;
}

40
OUTPUT:
[cse2@localhost ~]$ cc share.c
[cse2@localhost ~]$ ./a.out
Parent writing
abcdefghij
Child is reading
abcdefghij

Result:
Thus the program was executed and verified the output successfully.

41
Ex.No:6 MUTUAL EXCLUSION BY SEMAPHORE
Date:

Aim:
To wite the C program to perform Mutual Exclusion by Semaphore.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include <stdio.h>
int mutex=1 full-0.empry=3,x=0;
int main()
{
int n:
void producer();
void consumer);
int wait(int);
int signal(int);
printf "\n1,Producern2,Consumer\n3,Exit");
while(1)
{
printf("\nEnter your choice:");
scanf("%d", &n):

42
switch(n)
{
case 1: if((mutex==1)&&(empty!=0))
producer();
else
printf("Buffer is full!!");
break;
case 2: if(mutex==1)&&(full!=0))
consumer();
else
printf "Buffer is empty!!");
break;
case 3:exit(0);
break;
}
}
return 0;
}
int wait int s)
{
return (--s):
}
int signal( int s)
{
return(++s):
}
void producer()
{

43
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\nProducer produces the item "%d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full):
empty=signall(empty):
printf("\nConsumer consumes item %d",x);
x++
mutex=signal(mutex);
}

44
OUTPUT
1.Producer
2.Consumer
3.Exit
Enter your choice: 1
Producer produces the item 1
Enter your choice: 1
Producer produces the item 2
Enter your choice: 1
Producer produces the item 3
Enter your choice:2
Consumer consumes item 3
Enter your choice:2
Consumer consumes item 2

Result:
Thus the program was executed and verified the output successfully.

45
Ex.No:7 BANKERS ALGORITHM FOR DEAD LOCK AVOIDANCE
Date:
Aim:
To wite the C program to perform Bankers Algorithm for Dead Lock Avoidance.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include
#include
void main()
int r[1][10],av[1][10];
int all[10][10],max[10][10],ne[10][10],w[10],safe[10];
int i=0,j=0,k=0,1=0,np=0,nr=0.count=0,cnt=0;
clrscr();
printf("enter the number of processes in a system");
scanf("%d",&np);
printf "enter the number of resources in a system");
scanf("%d",&nr);
for(i=1;i<=nr;i++)
{
printf("\n enter the number of instances of resource R%d",i);

46
scanf("%d",&r[0][i]);
av[0][i]=r[0][i];
}
for(i=1;i<=np;i++)
for(j=1;j<=nr;j++)
all[i][j]=ne[i][j]=max[i][j]=w[i]=0;
printf Enter the allocation matrix");
for(i=1;i<=np:i++)
{
Printf( "\n");
for(j=1;j<=nr;j++)
{
scanf("%d",&all[i][j]);
av[0][j]=av[0][j]-all[i][j];
}
}
printf("\n Enter the maximum matrix");
for(i=1;i<=np;i++)
I printf("");
for(j=1;j<=nr;j++)
{
scanf("%d",&max[i][j]);
}
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nr;j++)
{

47
ne[i][j]=max[i][j]-all[i][j];
}
}
for(i=1;i<=np;i++)
{
printf("pocess P%d",i);
for(j=1;j<=nr;j++)
{
printf(“\n allocated %d", all[i][j]”);
printf("maximum %d\t",max[i][j]);
printf("need %d",ne[i][j]);
}
printf("\n___________________\n");
}
printf("\nAvailability");
for(i=1;i<=nr;i++)
printf("R%d %d\t",i,av[0][i]);
printf("\n______________ ");
printf("\n safe sequence");
for(count=1;count<=np;count++)
{
for(i=1;i<=np;i++)
{
cnt=0;
for(j=1;j<=nr;j++)
if(ne[i][j]<=av[0][j] && w[i]==0)
cnt++;
}

48
if(cnt==nr)
{
k++;
safe[k]=i;
for(l=1;1<=nr;l++) av[0][1]=av[0][l]+all[i][l];
printf("\n P%d ",safe[k]):
printf(" Availability");
for(l=1;1<=nr:1++) printf("R%d %d",1,av[0][1]);
w[i]=1;
}
}
}
getch();

Result:
Thus the program was executed and verified the output successfully.

49
Ex.No:8 DEADLOCK DETECTION ALGORITHM
Date:
Aim:
To wite the C program to perform Deadlock Detection Algorithm.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Algorithm:
1. Mark each process that has a row in the Allocation matrix of all zeros
2. Initialize a temporary vectorW to equal the Available vector.
3. Find an index i such that process i is currently unmarked and the throw Q is less than or equal
to W. That is, Qik... Wk, for I... k... m. If no such row is found, terminate the algorithm.
4. If such a row is found, mark processi and add the corresponding row of the allocation matrix
to W. That is, set Wk = Wk + Aik, for I... k... m. Return to step 3.
Program:
#include<stdio.h>
static int mark[20];
int I,j,np,nr;
int main()
{
int alloc[10][10],request[10][10], avail[10],r[10],w[10];
printf("Enter the no of process: ");
scanf("%d", &np);
printf("Enter the no of resources: ");
scanf("%d", &nr);

50
for(i=0;i<nr;i++)
{
printf("\nTotal Amount of the Resource R%d: "i+1);
scanf("%d",&r[i]);
}

printf("\nEnter the request matrix: ");


for(i=0;i<np;i++)
for(j=0;j<nr:j++)
scanf("%d", &request[i][j]);
printf("\nEnter the allocation matrix:");
for(i=0;i<np:i++)
for(j=0;j<nr;j++)
scanf("%d",&alloc[i][j]);
for(j=0;j<nr:j++)
{
avail[j]=r[j];
for(i=0;i<np;i++)
{
avail[j]=alloc[i][j];
}
}
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
{
if(alloc[i][j]==0)

51
count++
else
break;
}
if(count==nr)
mark[i]=1;
}
for(j=0;j<nr;j++)
w[j]=avail[j];
for(i=0;i<n;i++)
{
int canbeprocessed=0;
if(mark[i]!=1)
{
for(j=0;j<nr;j++)
{
If(request(i)<=w[j])
canbeprocessed=1:
else
{
canbeprocessed=0;
break;
}
}
if(canbeprocessed)
{
mark[i]=1;

52
for(j=0;j<nr:j++)
w[i]+=alloc[i][j];
}
}
}
int deadlock=0;
for(i=0;i<np:i++)
if(mark[i]!=1)
deadlock=1:
if (deadlock)
printf(" Deadlock detected":
else
printf("No Deadlock possible");
}

53
OUTPUT:
Enter the no of process: 4
Enter the no of resources: Total Amount of the Resource R1: 2
Total Amount of the Resource R2: 1
Total Amount of the Resource R3: 1 Total Amount of the Resource R4: 2
Total Amount of the Resource R5: 1
Enter the request matrix: 0 1 0 0 1
00101
00001
10101
Enter the allocation matrix: 1 0 1 1 0
11000
00010
00000
Deadlock detected

Result:
Thus the program was executed and verified the output successfully.

54
Ex. No:9 IMPLEMENT THREADING
Date:

Aim:
To wite the C program to implement Threading.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Algorithm:
1. Use the function pthread_create() to add a new thread of control to the current process. It is
prototyped by:
int pthread_create(pthread_t *tid, const pthread_attr_t *tattr, void ("start_routine) (void *). void
"arg);
2. When an attribute object is not specified, it is NULL, and the default thread is created with the
following attributes:

It is unbounded
It is nondetached
It has a a default stack and stack size
It inhetits the parent's priority

Program:
Thread creation
#include <unistd.h> //header file for sleep
#include<stdio.h>

55
#include<stdlib.h>
#include<pthread.h>
void mythread(void *vargp)
{
sleep(1):
printf "welcome");
return NULL
}
int main()
{
pthread_1 tid;
printf("before thread”);
pthread_create(&tid,NULL mythread,NULL);
pthread join(tid NULL);
exit(0);
}

OUTPUT
To compile
Cc filename.c --1 pthread
To Run
a.out

Result:
Thus the program was executed and verified the output successfully.

56
Ex.No:10 PAGING TECHNIQUE
Date:
Aim:
To wite the C program to implement paging technique.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<stdio.h>
int main();
{
int ms, ps, nop, np, rempages, I, j, x, y, pa, offset;
int s[10], fno[10][20];
clrscr();
Printf(“Enter the memory size”);
scanf(“%d”,&ms);
Printf(“Enter the page size – “);
scanf(“%d”,&ps);
nop= ms/ps;
Printf(“The no. of pages available in memory are -- %d “,nop):
Printf(“Enter number of processes – “);
Scanf(“%d”,&np);
rempages = nop;
for(i=1;i<=p;i++)

57
{
Print “Enter no. of pages required for p[%d]—“jk
Scanf(“%d”, &s[i]);
If(s[i] >rempages)
{
Printf(“Memory is Full”);
break;
}
Rempages = rempages s[i]:
Printf(“Enter pagetable for p[%d]”,i);
for(j=0;j<s[i];j++)
scanf(“%d”, &fno[i][j]);
}
Printf(“Enter Logical Address to find Physical Address “); printf(“Enter process no. and
pagenumber and offset “);
Scanf(“%d %d %d”, &x,&y. &offset):
If(x>np || y>=s[i] || offset>=ps)
printf(“Invalid Process or Page Number or offset”);
else
{
pa=fno[x][y]*ps+offset;
Printf(“\nThe Physical Address is --%d”,pa);
}
}

58
Output
Enter the memory size – 4
Enter the page size – 3
The no. of pages available in memory are – 1
Enter number of processes – 4
Enter no. of pages required for p[1]—2
Memory is Full

Result:
Thus the program was executed and the output is verified successfully.

59
Ex.No:11(a) MEMORY MANAGEMENT SCHEMES FIRST FIT
Date:

Aim:
To write the c program to implement memory management system first fit.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<stdio.h> #include<conio.h>
#define max 25
Void main()
{
Int frag/max),b[max][max],I,j,nb,nf,temp,highest-0: static int bbffmax,ff[max);
Clrscr();
Printf “Memory Management Scheme Worst Fit”);
Scanf(“%d”, &nb);
Printf(“Enter the number of blocks: “);
printf(“Enter the number of files:”);
scanf(“%d”,&nf);
Printf(“\nEnter the size of the blocks:-\n” );
for(i=1;i<=nb;i++)
{
Printf(“Block %d”,1);

60
Scanf(“%d”,&b[i]);
}
Printf(“Enter the size of the files :-“);
For(i=1,i<=nf;i++)

{
printf “File di);
scanf(“%d”,&f[i]);
}
for(i=1;i<=nf;i++)
{
for(i=1;j<=nb;j++)
{
If(bf[j]!=1) // if bf[j] is not allocated
{
temp=b[i]-f[i];
if(temp>=0)
if(highest<temp)
{
Ff[i]=j;
Highest =temp;
}
}
}
frag[i]=highest;
bf[lff[i]]=1;
highest=0;
}

61
Printf(“\nFile_no:\File size Block_no:Block_size:Fragement”); for(i=1;i<=nf;i++)
printf(“\n%d\t\t %d\t\t%d\t\t%d\t\t%d”,if[i]ff[i],b[ff[i]],frag[i]);
getch();
}

Output:
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4

File No File Size Block No Block Size Fragment


1 1 3 7 6
2 4 1 5 1

Result:
Thus the program was executed and the output verified successfully.

62
Ex.No:11(b) MEMORY MANAGEMENT SCHEMES BEST FIT
Date:

Aim:
To write the c program to implement memory management system best fit.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
Int frag[max].b[max] f[max].i.j.nb.nf.temp.lowest=10000;
static int bf[max],ff[max];
clrscr();
Printf(“Enter the number of blocks: “);
scanf(“%d”,&nb);
Printf(“Enter the number of files:”);
Scanf(“%d”,&nf);
Printf(“Enter the size of the blocks:-\n”);
for(i=1;i<=nb;i++)
{

63
Printf(“Block %d:”);
Scanf(“%d”, &b[i]);
}
Prinif “Enter the size of the files :-\n”);
for(i=1;i<=nf;i++)
{
Printf(“File %d;”,i);
scanf(“%d”,&f[i]);
}
for(i=1;i<=nf,i++)
{
for(j=1;j<=nb;j++)
{
If(bf[j]!=1)
{
Temp=b[j]f[i];
If(temp>=0)
If(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}

64
Printf(“\nFile No\tFile Size \tBlock NoltBlock Size\tFragment”);
for(i=1;i<=nf && ff[i]!=0;i++)
printf(“\n%d\t\t%d\t\t%d\t\t%d\t\t%d”,I,f[i],ff[i],b[ff[i]], frag[i]);
getch();
}

OUTPUT:
Enter the number of blocks: 3-
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4

File No File Size Block No Block Size Fragment


1 1 2 2 1
2 4 1 5 1

Result:
Thus the program was executed and the output is verified successfully.

65
Ex.No:12(a) FIFO PAGE REPLACEMENT ALGORITHM
Date:

Aim:
To write the c program to implement memory management system first fit.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<stdio.h>
#include <conio.h>
int i,j,nof,nor flag=0,refl 501,frm [50],pf=0,victim=1;
Void main()
{
Clrscr():
Printf(“\n \N FIFI PAGE REPLACEMENT ALGORITHM”):
Printf(‘n Enter no.of frames….”);
Scanf(“%d”, &nof);
printf(“Enter number of reference string..\n”);
scanf(“%d”,&nor);
printf(“n Enter the reference string..”);
for(i=0;i<nor;i++)
scanf(“%d”,&ref[i]);

66
printf(“\nThe given reference string: “);
for(i=0;i<nor;i++)
printf(“%4d”,ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf(“\n”);
for(i=0;i<nor;i++)
{
Flag=0;
Printf(“\n Reference np%d->\”ref[i]):
For(j=0;j<nof:j++)
{
If(frm[j]==ref[i])
{
Flag=1:
Break;
}
}
If(flag==0)
{
Victim++;
Victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
Printf(“%4d” frm[j]);
}
}
Printf(“\n\n\\ No.of pages faults… %d”,pf);

67
getch( );
}

OUTPUT:

FIFO PAGE REPLACEMENT ALGORITHM

Enter no.of frames….4


Enter number of reference string..
6
Enter the reference string..
564123
The given reference string:
……………………………………….. 5 6 4 1 2 3
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np1-> 5 6 4 1
Reference np2-> 2 6 4 1
Reference np3-> 2 3 4 1

No.of pages faults…6

Result:
Thus the program was executed and the output is verified successfully.

68
Ex.No:12(b) LRU PAGE REPLACEMENT ALGORITHM
Date:

Aim:
To write the c program to implement memory LRU page replacement algorithm.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include <stdio.h>
#include<conio.h>
int ij,nof,nor,flag=0,ref[50]frm[50],pf=0,victim=-1;
int recentl10) Irucall 301.count=0;
int Iruvictim();
Void main()
{
Clrscr():
Printf “VN LRU PAGE REPLACEMENT ALGORITHM”);
printf Enter no.of Frames….”);
scanf(“%d”,&nof);
printf(“Enter no.of reference string..”);
scanf(“%d”,&nor);

69
printf (“Enter reference string..”);
forti=0;i<nor;i++)
scan(“%d”,&ref[i]);
printf “viv LRU PAGE REPLACEMENT ALGORITHM “);
printf (“viv The given reference string: “);
printf(“……………………………..….”)
forti=0;i<nor;i++)
printf(“4d”.reflil);
for(i=1;i<=nof:i++)
{
frm[i]=-1:
Irucal[i]=0;
}
For(i=0;i<10;i++)
Recent[i]=0;
Printf(“\n”);
For(i=0;i<nor;i++)
{
flag=0;
printf(“\n\t Reference NO %d->\t”,ref[i]);
for(j=0;j<nof:j++)
{
if(frm[j]==ref[i])
flag=1;
break;
}
}
if(flag==0)

70
{
Count++;
If(count<=nof)
Victim++;
Else
Victim Iruvictim();
Pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf(“%4d” frm[j]);
}
recent[ref[i]]=i;
}
Printf(“in No.of page faults…%d”,pf);
getch();
}
Int Iruvictim()
{
int i,j,templ,temp2;
for(i=0;i<nof;i++)
{
Templ=frm[i];
Irucal[i]=recent[templ];
}
Temp2=Irucal[0];
for(j=1;j<nof:j++)
{
If(temp2>lrucal[j])

71
temp2=lrucal[j];
}
for(i=0;i<nof;i++)
if(refl temp2j==frm[i])
Return I;
Return 0;
}

OUTPUT:
LRU PAGE REPLACEMENT ALGORITHM
Enter no.of Frames….3
Enter no.of reference string..6
Enter reference string. 6 5 4 2 3 1
LRU PAGE REPLACEMENT ALGORITHM
The given reference string:
6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 31
No.of page faults…6

Result:
Thus the program was executed and the output is verified successfully.

72
Ex.No:13(a) SINGLE LEVEL DIRECTORY USING FILE ORGANIZATION
Date

Aim:
To write the c program to implement Single Level Directory using file organization.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include <stdio.h>
struct
{
char dname[10], fname [10][10];
int fcnt,
}dir;
void main()
{
int i,ch;
char
f[30];
clrscr();
dir.font = 0;
printf("\nEnter name of directory --");

73
scanf("%s", dir.dname);
while(1)
{
printf("\n\nl. Create File\t2. Delete file\t3. Search File \n4. Display Files\t5.Exit\nEnter your
choice -- ");
scanf( "%d", &ch);
switch(ch)
{
case I:
printf("\nEnter the name of the file --");
scanf( “%s” dir. fname[dir.fcnt]);
dir.font+ +;
break;
case 2:
printf("\nEnter the name of the file --");
scanf("%s"f);
for(i=O;i<dir.font:i++)
{
if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i], dir. fname[dir.fcnt-1]);
break;
}
}
if(i==dir.fcnt)
printf("File %s not found" ,f);
else
dir.fcnt
74
--
;
break;

case 3:
printf("\nEnter the name of the file--");
scanf("%s" ,f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir. fmame[i])==0)
{
printf( "File %s is found ", f);
break;
}
}
if(i==dir.fcnt)
printf(“File %s not found",f);
break;

case 4:
if(dir.fcnt==0)
printf( "\nDirectory Empty”);
else
{
printf("\nThe Files are --");
for(i=0;i<dir.fcnt; i++)
printf(" \t%s ",dir.fname[i]);
}

75
break;
default;
exit(0);
}
}
getch();
}

OUTPUT:
Enter name of directory --CSE
1. Create File
2.Delete File 3. Search File
4. Display Files
5. Bxit
Enter your choice -1
Enter the name of the file --A
1. Create File
2. Delete File 3. Search File
4. Display Files
5. Exit
Enter your choice -1
Enter the name of the file --B
1. Create File
2. Delete File 3. Search File
4. Display Files
5. Exit
Enter your choice -1
Enter the name of the file --C

76
1.Create File
2.Delete File 3. Search File
4.Display Files
5.Exit
Enter your choice -4
The Files are -A B C
1.Create File
2.Delete File 3. Search File
4.Display Files
5.Exit
Enter your choice -3
Enter the name of the file --ABC
File ABC not found
1. Create File
2. Delete File 3. Search File
4. Display Files
5. Exit
Enter your choice -2
Enter the name of the file -B
File B is deleted
1.Create File
2.Delete File 3. Search File
4.Display Files
5.Exit
Enter your choice -5
Result:
Thus the program was executed and the output is verified successfully.

77
Ex.No:13(b) TWO LEVEL DIRECTORY USING FILE ORGANIZATION
Date:

Aim:
To write the c program to implement Two level directory using file organization.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:

#include<stdio.h>
struct
{
char dname[10],fname[10][10] :
int fcnt;
}dir[10];
void main()
{
int i,ch,dcnt,k;
char f[30], d[30];
clrscr();
dcnt=0;
while(1)
{

78
printf("\n\nl. Create Directory \t2. Create File\t3. Delete File");
printf("\n4. Search File\t5. Display\t6.Exit\t Enter your choice--");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter name of directory --");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf( "Directory created");
break;

case 2:
printf("\nEnter name of the directory --");
scanf("%s",d):
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file --");
scanf("%s" dir[i].fnamel[dir[i].fcnt]);
dir[i].fcnt++;
printf("File created");
break;
}
if(i==dcnt)
printf("Directory %s not found",d);
break;

79
case 3:
printf("\nEnter name of the directory --");
scanf("%s",d);
for(i=0;i<dcnt; i++)
{
if{strcm
p(d,dir[i].dname)==0)
{
printf{ "Enter name of the file --");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f, dir[i].fname[k])==0)
{
printf("File %s is deleted ",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}
}
printf("File %s not found",f);
goto jmp;
}
}
printf( "Directory %s not found",d);
jmp : break;
case 4:
printf("\n Enter name of the directory --");

80
scanf("%s",d);
for(i=0;i<dcnt; i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf( "Enter the name of the file --");
scanf("%s",f);
for(k=0;k<dir[i],fcnt;k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File %s is found ",f);
goto jmpl;
}
}
printf( "File %s not found", f);
goto jmpl;
}
}
printf( "Directory %s not found",d);
jmp1: break;
case 5: if(dcnt==0)
printf(“\nNo Directory’s ");
else
{
printf(“\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{

81
printf("\n%s\t\t ", dir[i].dname);
for(k=0;k<dir[i].fcnt;k+ +)
printf("\t %s",dir[i].fname[k]);
}
}
break;
default:exit(0);
}
}
getch();
}

OUTPUT:
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --1
Enter name of directory --DIRI
Directory created
1.Create Directory
2.Create File
3.Delete File
4.Search File
5.Display

82
6.Exit
Enter your choice --1
Enter name of directory --DIR2
Directory created
1.Create Directory
2.Create File
3.Delete File
4.Search File
5.Display
6.Exit
Enter your choice --2
Enter name of the directory -DIR 1
Enter name of the file--A1
File created
1.create Directory
2.create File
3.Delete File
4.Search File
5.Display
6.Exit
Enter your choice --2
Enter name of the directory -DIR 1
Enter name of the file--A2
File created
1.Create Directory
2.Create File
3.Delete File
4.Search File

83
5.Display
6.Exit
Enter your choice --2
Enter name of the directory -DIR2
Enter name of the file--B 1
File created
1. Create Directory
2. Create Eile
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --5
Directory Files
DIR 1
Al
A2
DIR2
Bl
1. Create Directory
2. Create Eile
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --4
Enter name of the directory -DIR
Directory not found

84
1.Create Directory
2.Create File
3.Delete File
4.Search File
5.Display
6.Exit
Enter your choice --3
Enter name of the directory -DIRI
Enter name of the file --A2
File A2 is deleted
1.Create Directory
2.Create File
3.Delete File
4.Search File
5.Display
6.Exit
Enter your choice --6

Result:
Thus the program was executed and the output is verified successfully.

85
Ex:No:14(a) SEQUENTIAL FILE ALLOCATION
Date:

Aim:
To write the c program to allocate the give file in a Sequential file Allocation.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program
#include<stdio.h>
#include<conio.h>
main()
{
Int n,i,j,b[20],sb[20],t[20],x,c[20][20]: cIrscr():
printfi"Enter no.of files:"); scanfi'"%d",&n);
for(i=0;i<n;i++)
}
{
printf( "Enter no. of blocks occupied b% file%d",1+1); scanfl"%d",&bfif);
printr Enter the starting block of file%d",i+11: scanfi'"%d",&sb(ii);
for(j=0;j<blif,j++)
cliffil=sb[i]++;
}
prinffi'"Filename\iStart blockViength\n"); for(i=0;i<n;i++)

86
printfi "%dV %d V%cAn",i+1.01,b(il); printfi"Enter file name:");
scanfi"%d",&x);
printfi'"File name is:%d",.v1; print'? "length is:%d".blx-11: printfi"blocks occupied:");
.forti=0;i<blx-1ki++1
printfi"%4d",c1x- I);
getcht);
}
OUTPUT:
Enter no.of tiles: 2
Enter no. of blocks occupied by filel 4 Enter the starting block of file 1 2
Enter no. of blocks occupied by file 2 10 Enter the starting block of file 2 5

Filename Start block length


I 2 4
2 5 10
Enter file name: rajesh
File name is:12803 length is: Oblocks occupied.

Result:
Thus the program was executed and verified the output successfully.

87
Ex.No:14(b) INDEXED FILE ALLOCATION
Date:

Aim:
To write the c program to allocate the give file in a Index file Allocation.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
litnclude<stdto.h>
#include<conio.h>
main()
{
int n,m[201,i,j,sb1201,420],b(20#201,x, cIrscr();
print/ "Enter no. of files:"); scanft"%d",(1n);
for(i=0;i<n;i++)
}
{
printft"Enter starting block and size of file%d:",1+1);
scanft"%d%d",AsKibctsfil);
printft"Enter blocks occupied by file%d:".1+1);
scanft"%d",(Inifil);
prindt"enter blocks of file%d:",i+1);
for0=0;j<mji],j++)

88
scanf("%d",&b[i][j]);
} printft'1nFileV index\tlength\n");
for(i=0;i<n;i++)
{
print( "%dv%d■ad\n",i+ ,sbfi 1,mfi I );
}printftutnEnter file name:");
scanft"%d",&x);
printft'file name is:%dVi".x); i=.r-/;
printft"Index is:%d",sb[i]);
printf("Block occupied are:"):
for(j=0;j<mlif;j++)
printft"%3d",b1110));
Retch();
OUTPUT:
Enter no. of files:2
Enter starting block and size of file!: 2 5
Enter blocks occupied by filet : 10
enter blocks of file 1:3
254672647
Enter starting block and size of file2: 3 4
Enter blocks occupied by file2:5
enter blocks of file 2: 2 3 4 5 6
File index length
1 2 10
2 3 5

Result:
Thus the program was executed and the output is verified successfully.

89
EX: NO: 15(a) FCFS DISK SCHEDULING
Date:

Aim:
To write the c program to schedule the given input in FCFS Disk Scheduling.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program
#include<stdio.h>
#include<sidlib.h>
int main( )
{
int RQf 100],i,n,TotalHeadMoment=0,initial;
printft"Enter the number of Requests\n");
scanfi"%d",ctn);
printft"Enter the Requests sequence\n");
for(i=0;i<n;i+-F)
scanft"%d",&RQ[i]);
prinOrEnter initial head position\n");
scanft "%d", & initial );
// logic for FCFS disk scheduling
For(i=0;i<n;i++)

90
{TotalHeadMoment=TotalHeadMoment+abs(RQ1d-initial);
initial=RQ[i];
}
printft"Total head moment is return 0;
}
Output
Enter the number of Request 8

Enter the Requests Sequence


95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644

Result:
Thus the program was executed and the output is verified successfully.

91
Ex.No:15(b) SSTF DISK SCHEDULING
DATE:

Aim:
To write the c program to schedule the given input in FCFS Disk Scheduling.
Procedure:
Step 1: Open turbo C IDE, click on File and then click → New.
Step 2: Write the C program.
Step 3: Press Alt + F9 to compile the code.
Step 4: Press Ctrl + F9 to run the code.
Step 5: Write the output.

Program:
#include<sidio.h>
#inelude<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanfl"%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQW);
priny("Enter initial head position\n"); scanft"%d",&initial);
// logic for sstf disk scheduling
/* loop will execute until all process is completed */ while(count!=n)
{

92
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQW-initial);
if(min>d)
{
min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min; initial=R0index];
// 1000 is for max
// you can use any number
RQ [index]=1000
-count++
}
Printf( "Total head movement is %d”,TotalHeadMoment);
return 0;
}
Output
Enter the number of Request
8
Fitter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
Result:
Thus the program was executed and verified the output successfully.

93
Ex:No:16 INSTALL ANY GUEST OPERATING SYSTEM LIKE
DATE: LINUX USING VMWARE

Aim:
To install any Guest Operating System like Linux using VM ware
Procedure:
Steps to install and configure VMWare:
Step 1: Download the VMWare workstation. Set up is around 307 MB. Currently, version
12 is available. Please note we have set up screens on version I I.
Step 2: Install VMWare on your machine. Setup is simple and requires clicking Next button a
couple of times.
Step 3: After installation open the VMWare workstation by using either the start menu or
shortcut created on the desktop.
Step 4: Click on "Create a New Virtual Machine".

Step 5: With default "Typical" selected click on the Next button.

94
Step 6: Specify the path of the operating system setup file.

Step 7: In the Next step you need to specify a key or a serial number of the operating system. If
you are using the trial version then that part can be skipped.
Step 8: Enter the name for the virtual machine and specify a path to the directory where you
want to create your virtual machine. It is recommended that the drive you're selecting to install a
virtual machine should have sufficient space.

95
Step 9: Specify the amount of disk space you want to allocate for a virtual machine. Allocate
disk space according to the size of the software you are going to install on the virtual machine.

Step 10: On the next screen it will show the configuration you selected for a virtual machine.

96
Step 11: It will allocate Hardware according to the default settings but you can change it by
using Customize Hardware button in the above screen.
You can specify what amount of RAM, a processor has to be allocated for a virtual machine.
Do not allocate complete RAM or a complete Processor for a v irtual machine. Also, do not
allocate very little RAM or processor. Leave default settings or allocate in such a way that your
application should be able to run on the virtual machine. Else it
will result in a slow virtual machine.

Step 12: Click on the Finish button to create the virtual machine at the specified location and
with specified resources.
If you have specified a valid file
(Aso, .rar., .nrg) for the operating system it will

97
take standard time to complete the operating system setup on the virtual machine, and then it will
be ready to use your regular OS.

Result:
Thus the installation of any guest operating system like linux using vmware is completed
successfully.

98

You might also like