0% found this document useful (0 votes)
2 views86 pages

OS Lab

The document outlines the installation process for Windows 7, detailing system requirements and step-by-step instructions for installation using a DVD. It also covers basic UNIX commands, including date, calendar, echo, and file management commands, along with examples of shell programming for arithmetic operations, number checking, and process management. Additionally, it includes sample code for various shell scripts and system calls.

Uploaded by

Vijay Chellappan
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)
2 views86 pages

OS Lab

The document outlines the installation process for Windows 7, detailing system requirements and step-by-step instructions for installation using a DVD. It also covers basic UNIX commands, including date, calendar, echo, and file management commands, along with examples of shell programming for arithmetic operations, number checking, and process management. Additionally, it includes sample code for various shell scripts and system calls.

Uploaded by

Vijay Chellappan
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

EX.

NO:1
Date: Installation of windows operating system

AIM:

WINDOWS 7 SYSTEM REQUIREMENTS:

 1 gigahertz (GHz) or faster 32-bit (x86) or 64-bit (x64) processor*


 1 gigabyte (GB) RAM (32-bit) or 2 GB RAM (64-bit)
 16 GB available hard disk space (32-bit) or 20 GB (64-bit)
 DirectX 9 graphics device with WDDM 1.0 or higher driver
 DVD drive
 Internet access (optional)
INSTALLING USING A WINDOWS 7 INSTALLATION DVD:

STEP 1: ENTER YOUR COMPUTER’S BIOS.

Turn off the computer that you want to install Windows on then turn it back on. When the BIOS
screen appears or you are prompted to do so, press Del, Esc, F2, F10, or F9 (depending on your
computer’s motherboard) to enter the system BIOS. The key to enter the BIOS is usually shown on
the screen.

3
STEP 2: FIND YOUR BIOS’S BOOT OPTIONS MENU.

The boot options menu of your BIOS may vary in location or name from the illustration, but you
may eventually find it if you search around.

 If you can’t find the boot options menu, search the name of your BIOS (most likely located
in the BIOS menu) online for help.

STEP 3 : SELECT THE CD-ROM DRIVE AS THE FIRST BOOT DEVICE OF YOUR
[Link] this method may vary among computers, the boot options menu is typically
a menu of movable device names where you should set your CD-ROM drive as the first boot device.

4
STEP 4: SAVE THE CHANGES OF THE SETTINGS.

Press the button indicated on the screen or select the save option from the BIOS menu to save your
configuration.

STEP 5 : SHUT OFF YOUR COMPUTER.

STEP 6 : POWER ON THE PC AND THE INSERT THE WINDOWS 7 DISC INTO
YOUR CD/DVD DRIVE.

STEP 7 : START YOUR COMPUTER FROM THE DISC.

After you have placed the disc into the disc drive, start your computer. When the computer starts,
press a key if you are asked if you would like to boot from the disc by pressing any key. After you
choose to start from the disc, Windows Setup will begin loading. If you are not asked to boot from
the disc, you may have done something wrong. Retry the previous steps to solve the problem.

5
STEP 8 : CHOOSE YOUR WINDOWS SETUP OPTIONS.

Once Windows Setup loads, you’ll be presented with a window. Select your preferred language,
keyboard type, and time/currency format, then click Next.

STEP 9 : CLICK THE INSTALL NOW BUTTON.

6
STEP 10 : ACCEPT THE LICENSE TERMS.

Read over the Microsoft Software License Terms, check I accept the license terms, and click Next.

STEP 11 : SELECT THE CUSTOM INSTALLATION.

STEP 12 : DECIDE ON WHICH HARD DRIVE AND PARTITION YOU WANT TO


INSTALL WINDOWS ON.

A hard drive is a physical part of your computer that stores data, and partitions “divide” hard drives
into separate parts.

 If the hard drive has data on it, delete the data off of it, or format it.
 Select the hard drive from the list of hard drives.
 Click Drive options (advanced).

7
 Click Format from Drive options.
 If your computer doesn’t have any partitions yet, create one to install Windows on it.
 Select the hard drive from the list of hard drives.
 Click Drive options (advanced).
 Select New from Drive options.
 Select the size, and click OK.

STEP 13 : INSTALL WINDOWS ON YOUR PREFERRED HARD DRIVE AND


PARTITION.

Once you’ve decided on where to install Windows, select it and click Next. Windows will begin
installing.

RESULT:

8
[Link]:2A
Date: Basics of UNIX commands

AIM:

COMMANDS:

[Link] 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‟ format
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
u = Week of the year.
y = Display the year in 2 digit.

9
Y = Display the full year.
Z = Time zone .

To change the format :


Syntax :
$date „+%H-%M-%S‟

[Link] 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 Syntax gives
the calendar of reserved month of that year.

[Link] Command :
This command is used to print the arguments on the screen .
Syntax : $echo <text>

[Link] Command :
It is used to display the arguments in „#‟ symbol .
Syntax : $banner <arguments>

5.’who’ Command :
It is used to display who are the users connected to our computer currently.
Syntax : $who – option‟s
Options : -
H–Display the output with headers.
b–Display the last booting date or time or when the system was lastely rebooted.

10
6.’who am i’ Command :
Display the details of the current working directory.
Syntax : $who am i

9.’CLEAR’ Command :
It is used to clear the screen.
Syntax : $clear

10.’MAN’ Command :
It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .
Syntax : $man <command name>

[Link] 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.
r- 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:

[Link] Working Directory Command :


To print the complete path of the current working directory.
Syntax : $pwd

[Link] Command :

11
To create or make a new directory in a current directory .
Syntax : $mkdir <directory name>

[Link] Command :
To change or move the directory to the mentioned directory .
Syntax : $cd <directory name.

[Link] Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>
FILE RELATED COMMANDS:

[Link] 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.

[Link] A FILE :
To display the content of file mentioned we use CAT command without „>‟ operator.
Syntax : $cat <filename.
Options –s = to neglect the warning /error message.

[Link] CONTENTS :
To copy the content of one file with another. If file doesnot exist, a new file is 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>

[Link] A FILE :

12
To sort the contents in alphabetical order in reverse order.
Syntax :
$sort <filename >
Option : $ sort –r <filename>

[Link] CONTENTS FROM ONE FILE TO ANOTHER :


To copy the contents from source to destination file . so that both contents are same.
Syntax :
$cp <source filename><destination filename>
$cp <source filename path ><destination filename path>

[Link] Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax :
$ mv <source filename><destination filename>

[Link] Command :
To permanently remove the file we use this command .
Syntax :
$rm <filename>

[Link] Command :
To list the content count of no of lines , words, characters .
Syntax :
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.

FILTERS AND PIPES

13
HEAD : It is used to display the top ten lines of file.
Syntax: $head<filename>

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
tocontinue scrolling.
Syntax: $ls –a\p

MORE :It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.
Syntax: $more<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 channelled 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]”

RESULT:

14
EX. NO: 2B1 BASIC ARITHMETIC OPERATION USING SHELL
DATE: PROGRAMMING

AIM:

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

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

15
OUTPUT:
[2mecse25@rhes3linux ~]$ sh [Link]
Enter the a vale
10
Enter b value
50
sum:60
sub:-40
mul:500
div:0

RESULT:

16
EX. NO: 2B2 NUMBER CHECKING USING SHELL PROGRAM
DATE:

AIM:

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:
odd no
even no
odd no
even no
odd no
even no
odd no
even no
RESULT:

17
EX. NO: 2B3 MULTIPLICATION TABLE USING SHELL PROGRAM
DATE:

AIM:

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:
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:

18
EX. NO: 2B4 USING IF STATEMENT IN SHELL PROGRAMING
DATE:
AIM:

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/sh
echo "Enter a number:"
read num
if [ $num -gt 0 ]
then
echo "The number is positive."
elif [ $num -lt 0 ]
then
echo "The number is negative."
else
echo "The number is zero."
fi

OUTPUT:
Enter a number:
-2
The number is negative.
RESULT:

19
EX. NO: 2B5 SIMPLE FUNCTION IN SHELL PROGRAMING
DATE:
AIM:

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:

addition = 15

RESULT:

20
EX. NO: 3.1 PROCESS MANAGEMENT USING Fork, Exit, Getpid, SYSTEM
DATE: CALLS

AIM :

ALGORITHM :
Step 1 : Declare the variable pid.
Step 2 : Get the pid value using system call fork().
Step 3 : If pid value is less than zero then print as “Fork failed”.
Step 4 : Else if pid value is equal to zero include the new process in the system‟s file
using execlp system call.
Step 5 : Else if pid is greater than zero then it is the parent
process and it waits till the child completes using the system callwait()
Step 6 : Then print “Child complete”.

PROGRAM CODING :
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main(int argc,char *arg[])
{
int pid;
pid=fork();

if(pid<0)
{
printf("fork failed");
exit(1);
}
else if(pid==0)
{

21
execlp("whoami","ls",NULL);
exit(0);
}
else
{
printf("\n Process id is -%d\n",getpid());

wait(NULL);
exit(0);
}}

OUTPUT:
[cse6@localhost Pgm]$ cc prog4a.c
[cse6@localhost Pgm]$ ./[Link]
Process id -4876

RESULT:

22
EX. NO: 3.2 PROCESS MANAGEMENT USING Wait,Close
DATE: SYSTEM CALLS

AIM :

ALGORITHM :
Step 1 : Declare the variables pid and i as integers.
Step 2 : Get the child id value using the system call fork().
Step 3 : If child id value is less than zero then print “fork failed”.
Step 4 : Else if child id value is equal to zero , it is the id value of the child and then start the
child process to execute and perform Steps 6 & 7.
Step 5 : Else perform Step 8.
Step 6 : Use a for loop for almost five child processes to be called.
Step7 : After execution of the for loop then print “child process ends”.
Step 8 : Execute the system call wait( ) to make the parent to wait for the child process
to get over.
Step 9 : Once the child processes are terminated , the parent terminates and hence print
“Parent process ends”.
Step 10 : After both the parent and the chid processes get terminated it execute the wait( )
system call to permanently get deleted from the OS.

PROGRAM CODING:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
int status;
// Create a child process
pid = fork();
if (pid == -1) {
perror("fork");

23
exit(EXIT_FAILURE);
}
if (pid == 0) {
// This is the child process
printf("Child process running with PID %d\n", getpid());
sleep(3);
printf("Child process exiting\n");
exit(EXIT_SUCCESS);
} else {
// This is the parent process
printf("Parent process running with PID %d\n", getpid());
// Wait for the child process to exit
if (wait(&status) == -1) {
perror("wait");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("Child process exited with status %d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("Child process terminated by signal %d\n", WTERMSIG(status));
}
}
return 0;
}

OUTPUT:
Parent process running with PID 701
Child process running with PID 705
Child process exiting
Child process exited with status 0

RESULT:

24
EX. NO: 4.1 C PROGRAM TO IMPLEMENT CPU SCHEDULING
DATE: ROUND ROBIN SCHEDULING

AIM :

ALGORITHM:
Step 1: Initialize all the structure elements
Step 2: Receive inputs from the user to fill process id,burst time and arrival time.
Step 3: Calculate the waiting time for all the process id.
i) The waiting time for first instance of a process is calculated as:
a[i].waittime=count + a[i].arrivt
ii) The waiting time for the rest of the instances of the process is calculated as:

a) If the time quantum is greater than the remaining burst time then waiting time is
calculated as:
a[i].waittime=count + tq
b) Else if the time quantum is greater than the remaining burst time then waiting
time is calculated as:
a[i].waittime=count - remaining burst time
Step 4: Calculate the average waiting time and average turnaround time
Step 5: Print the results of the step 4.

PROGRAM:

#include<stdio.h>
void main()
{
int i,tbt=0,nop,ts=0,flag[20], rem[20];
int from,wt[20],tt[20],b[20], twt=0,ttt=0;
int dur;
float awt,att;
printf("Enter no. of Processes: ");
scanf("%d",&nop);

25
printf("Enter the time slice: ");
scanf("%d",&ts);
printf("Enter the Burst times..\n");
for(i=0;i<nop;i++)
{
wt[i]=tt[i]=0;
printf("P%d\t: ",i+1);
scanf("%d",&b[i]);
rem[i]=b[i];
tbt+=b[i];
flag[i]=0;
}
from=0;
i=0;
printf("\n\t Gantt Chart");
printf("\n ProcessID\tFrom Time\tTo Time\n");
while(from<tbt)
{
if(!flag[i])
{
if(rem[i]<=ts)
{
dur=rem[i];
flag[i]=1;
tt[i]=dur+from;
wt[i]=tt[i]-b[i];
}
else
dur=ts;
printf("%7d%15d%15d\n",i+1, from,from+dur);
rem[i] -= dur;
from += dur;
}
i=(i+1)%nop;

26
}
for(i=0;i<nop;i++)
{
twt+=wt[i];
ttt+=tt[i];
}
printf("\n\n Process ID \t Waiting Time \t Turn Around Time");

for(i=0;i<nop;i++)
{
printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);
}
awt=(float)twt/(float)nop;
att=(float)ttt/(float)nop;
printf("\nTotal Waiting Time:%d",twt); printf("\nTotal
Turn Around Time:%d",ttt); printf("\nAverage Waiting
Time:%.2f",awt); printf("\nAverage Turn Around
Time:%.2f\n",att); }

OUTPUT:

Enter no. of Processes: 3

Enter the time slice: 3

Enter the Burst times.. P1 : 24

P2 :5

P3 :3

Gantt Chart

ProcessID From Time To Time

27
1 0 3

2 3 6

3 6 9

1 9 12

2 12 14

1 14 17

1 17 20

1 20 23

1 23 26

1 26 29

1 29 32

Process ID Waiting Time Turn Around Time


1 8 32
2 9 14
3 6 9
Total Waiting Time:23
Total Turn Around Time:55
Average Waiting Time:7.67

Average Turn Around Time:18.33

RESULT:

28
EX. NO: 4.2 C PROGRAM TO IMPLEMENT CPU SCHEDULING
DATE: SHORTEST JOB FIRST

AIM:

ALGORITHM:

Step 1: Get the number of process.


Step 2: Get the id and service time for each process.

Step 3: Initially the waiting time of first short process as 0 and total time of first
short is process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.

Step 5: Waiting time of one process is the total time of the previous process. Step 6:
Total time of process is calculated by adding the waiting time and servicetime of each
process.
Step 7: Total waiting time calculated by adding the waiting time of each process.
Step 8: Total turn around time calculated by adding all total time of each process. Step
9: Calculate average waiting time by dividing the total waiting time by totalnumber of
process.
Step 10: Calculate average turn around time by dividing the total waiting time by
total number of process.
Step 11: Display the result.

PROGRAM:
#include<stdio.h>
int main()
{
int n,w[100],tot[100],i,j,awt,atot; float avwt,avtot;
struct
{

29
int p,bt; }sjf[10],temp;

printf("Enter the number of Processes:"); scanf("%d",&n);


for(i=1;i<=n;i++)

{
printf("Enter the Burst time for Process%d : ",i); scanf("%d",&sjf[i].bt);
sjf[i].p=i;

}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(sjf[j].bt>sjf[i].bt)
{
temp=sjf[i];
sjf[i]=sjf[j];
sjf[j]=temp;
}
w[1]=0;
tot[1]=sjf[1].bt;
for(i=2;i<=n;i++) tot[i]=tot[i-1]+sjf[i].bt;

awt=0;
atot=0;
for(i=1;i<=n;i++)
{

w[i]=tot[i]-sjf[i].bt; awt+=w[i]; atot+=tot[i];

}
avwt=(float)awt/n;

avtot=(float)atot/n;

30
printf("\n\nProcessId\tWaiting time\t TurnaroundTime");

for(i=1;i<=n;i++)
printf("\n\t%d\t\t%d\t\t%d",sjf[i].p,w[i],tot[i]);
printf("\n\nTotal Waiting Time :%d",awt);
printf("\n\nTotal Turnaround Time :%d",atot);
printf("\n\nAverage Waiting Time :%.2f",avwt);

printf("\n\nAverage Turnaround Time :%.2f",avtot); }

OUTPUT:

Enter the number of Processes:3


Enter the Burst time for Process1 : 24
Enter the Burst time for Process2 : 5
Enter the Burst time for Process3 : 3

ProcessId Waiting time TurnaroundTime


3 0 3
2 3 8
1 8 32
Total Waiting Time :11
Total Turnaround Time :43
Average Waiting Time :3.67
Average Turnaround Time :14.33

RESULT:

31
EX. NO: 4.3 C PROGRAM TO IMPLEMENT CPU SCHEDULING
DATE: FIRST COME FIRST SERVE

AIM:

ALGORITHM:
Step 1: Create the number of process.
Step 2: Get the ID and Service time for each process.
Step 3: Initially, Waiting time of first process is zero and Total time for the first
process is the starting time of that process.

Step 4: Calculate the Total time and Processing time for the remaining
processes. Step 5: Waiting time of one process is the Total time of the previous
process. Step 6: Total time of process is calculated by adding Waiting time and
Servicetime.
Step 7: Total waiting time is calculated by adding the waiting time for lack
process. Step 8: Total turn around time is calculated by adding all total time of each
process. Step 9: Calculate Average waiting time by dividing the total waiting time by
totalnumber of process.
Step 10: Calculate Average turn around time by dividing the total time by the
number of process.
Step 11: Display the result.

PROGRAM:
#include<stdio.h>
int main()
{
int n,b[10],t=0,i,w=0,r=0,a=0; float
avg,avg1;
printf("\nEnter number of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : \n");
for(i=1;i<=n;i++) scanf("%d",&b[i]);
printf("\n Gantt chart ");

32
for(i=1;i<=n;i++)

printf("P%d\t",i);
printf("\n\nProcess BurstTime WaitingTime TurnaroundTime\n");
for(i=1;i<=n;i++)
{
t=t+w;
r=r+b[i];
printf("P%d\t\t%d\t\t%d\t\t%d\t\t\n",i,b[i],w,r);
w=w+b[i];
a=a+r;
}
avg=(float)t/n;
avg1=(float)a/n;
printf("\n Average WaitingTime is %f",avg); printf("\n
Average TurnaroundTime is %f\n",avg1); return(0);}

OUTPUT:

Enter number of processes : 3


Enter the burst times :
24
5
3

Gantt chart P1 P2 P3

Process BurstTime WaitingTime TurnaroundTime


P1 24 0 24
P2 5 24 29
P3 3 29 32
Average WaitingTime is 17.666666
Average TurnaroundTime is 28.333334

RESULT:

33
EX. NO: 4.4 C PROGRAM TO IMPLEMENT CPU SCHEDULING
DATE: PRIORITY SCHEDULING

AIM:

ALGORITHM:
Step 1: Get the number of process
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time of first short
is process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.
Step 5: Waiting time of one process is the total time of the previous process.
Step 6: Total time of process is calculated by adding the waiting time and service time of
each process.
Step 7: Total waiting time calculated by adding the waiting time of each process.
Step 8: Total turn around time calculated by adding all total time of each process.
Step 9: Calculate average waiting time by dividing the total waiting time by total
number of process.
Step 10: Calculate average turn around time by dividing the total waiting time by total
number of process.
Step 11: Display the result.

PROGRAM CODING:
#include<stdio.h>
int main()
{
int n,temp=0,w[20],b[20], p[20],
t2[20],j,t1,d[20],i,
te=0,b1[20],t3=0;
float t,r;
w[1]=0;
printf("\nEnter no. of processes:");

34
scanf("%d",&n);
printf("\nEnter the burst times : ");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&b[i]); d[i]=i;
}
printf("Enter the priorities:");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&p[i]);
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(p[i]<p[j])
{
temp=p[i];
t1=d[i];
te=b[i];
p[i]=p[j];
d[i]=d[j];
b[i]=b[j];
p[j]=temp;
d[j]=t1;
b[j]=te;
}
printf("\nGantt Chart : ");
for(i=1;i<=n;i++) printf("P%d\t",d[i]);
printf("\nProcess \t Priority\tBurst Time\t Waiting Time\t Turnaround Time");
for(i=1;i<=n;i++)
{
t=d[i];
w[i+1]=w[i]+b[i];

35
t2[i]=b[i]+w[i];
t3+=t2[i];
printf("\nP%d\t\t%d\t\t%d\t\t%d\t\t%d",d[i],p[i],b[i],w[i],t2[i]);
}
temp=0;
for(i=1;i<=n;i++)
temp+=w[i];
t=(float)temp/n;
r=(float)t3/n;
printf("\nAverage Waiting time : %.2f",t);
printf("\nAverage Turnaround time : %.2f",r);

OUTPUT:
Enter the no. of processes : 3 Enter the
burst times
P1 : 24
P2 : 5
P3 : 3
Enter the priorities

P1 : 2

P2 : 1
P3 : 3
Gantt Chart : P2 P1P3
ProcessID Priority BurstTime WaitingTime TurnaroundTime

P2 1 5 0 5
P1 2 24 5 29
P3 3 3 29 32

Average Waiting Time : 11.33


Average Turnaround Time : 22.00
RESULT:

36
EX. NO: 5 IILUSTRATE THE INTER PROCESS COMMUNICATION
DATE: STRATEGY

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM CODING
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHM_SIZE 1024
int main() {
int shmid;
char *shmaddr;
key_t key = 5678;
// create shared memory segment
if ((shmid = shmget(key, SHM_SIZE, IPC_CREAT | 0666)) < 0) {
perror("shmget");
exit(1);
}
if ((shmaddr = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
exit(1);

37
}
// write message to shared memory
strncpy(shmaddr, "Hello, world!", SHM_SIZE);
// fork process
pid_t pid = fork();
if (pid < 0) {
perror("fork");
exit(1);
} else if (pid == 0) {
// child process
printf("Child process reading from shared memory: %s\n", shmaddr);
exit(0);
} else {
// parent process
wait(NULL);
printf("Parent process wrote to shared memory: %s\n", shmaddr);
// detach shared memory segment
if (shmdt(shmaddr) == -1) {
perror("shmdt");
exit(1);
}
// remove shared memory segment
if (shmctl(shmid, IPC_RMID, NULL) == -1) {
perror("shmctl");
exit(1);
} }
return 0;
}

Output:
Child process reading from shared memory: Hello, world!
Parent process wrote to shared memory: Hello, world!
RESULT:

38
EX. NO: 5 IMPLEMENT MUTUAL EXCLUSION BY SEMAPHORE
DATE:

AIM:

ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process

i) Produce an item in to temporary variable.


ii) If there is empty space in the buffer check the mutex value for enter into the critical section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable to the
buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove item
from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result

PROGRAM CODING

#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n [Link]\[Link]\[Link]\n");
while(1)

39
{
printf(" \nenter ur choice");
scanf("%d",&n);
switch(n)
{
case 1:if((mutex==1)&&(empty!=0))
producer();
else
printf("buffer is full\n");
break;
case 2:if((mutex==1)&&(full!=0))
consumer();
else
printf("buffer is empty");
break;
case 3:exit(0);
break;
}
}
}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;

40
printf("\n producer produces the items %d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes the item %d",x);
x--;
mutex=signal(mutex);
}

OUTPUT:

Produced element a
Consumed element a
Produced element b
Consumed element b
Produced element c
Consumed element c
Produced element d
Consumed element d
Produced element e
Consumed element e
Produced element f
Consumed element f
Produced element g
Consumed element g
Produced element h
Consumed element h

RESULT:

41
EX. NO: 7 C PROGRAM TO AVOID DEADLOCK USING BANKER’S
DATE: ALGORITHM

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM CODING
// Banker's Algorithm
#include <stdio.h>
intmain()
{
// P0, P1, P2, P3, P4 are the Process names here
intn, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
intalloc[5][3] = { { 0, 1, 0 }, // P0 // Allocation Matrix
{ 2, 0, 0 }, // P1
{ 3, 0, 2 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4

intmax[5][3] = { { 7, 5, 3 }, // P0 // MAX Matrix


{ 3, 2, 2 }, // P1
{ 9, 0, 2 }, // P2
{ 2, 2, 2 }, // P3

42
{ 4, 3, 3 } }; // P4

intavail[3] = { 3, 3, 2 }; // Available Resources

intf[n], ans[n], ind = 0;


for(k = 0; k < n; k++) {
f[k] = 0;
}
intneed[n][m];
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++)
need[i][j] = max[i][j] - alloc[i][j];
}
inty = 0;
for(k = 0; k < 5; k++) {
for(i = 0; i < n; i++) {
if(f[i] == 0) {

intflag = 0;
for(j = 0; j < m; j++) {
if(need[i][j] > avail[j]){
flag = 1;
break;
}
}

if(flag == 0) {
ans[ind++] = i;
for(y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}

43
}

intflag = 1;

for(inti=0;i<n;i++)
{
if(f[i]==0)
{
flag=0;
printf("The following system is not safe");
break;
}
}

if(flag==1)
{
printf("Following is the SAFE Sequence\n");
for(i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}

return(0);

Output:
Following is the SAFE Sequence
P1 -> P3 -> P4 -> P0 -> P2

RESULT:

44
EX. NO: 8 C PROGRAM TO IMPLEMENT DEADLOCK DETECTION
DATE: ALGORITHM

AIM

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in data types.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution
//Deadlock Detection algorithm implementation

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("\nEnter the no of process: ");


scanf("%d",&np);
printf("\nEnter the no of resources: ");
scanf("%d",&nr);
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:");

45
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]);
/*Available Resource calculation*/
for(j=0;j<nr;j++)
{
avail[j]=r[j];
for(i=0;i<np;i++)
{
avail[j]-=alloc[i][j];
}
}
//marking processes with zero allocation
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
{
if(alloc[i][j]==0)
count++;
else
break;
}
if(count==nr)
mark[i]=1;
}
// initialize W with avail
for(j=0;j<nr;j++)
w[j]=avail[j];

46
//mark processes with request less than or equal to W
for(i=0;i<np;i++)
{
int canbeprocessed=0;
if(mark[i]!=1)
{
for(j=0;j<nr;j++)
{
if(request[i][j]<=w[j])
canbeprocessed=1;
else
{
canbeprocessed=0;
break;
}
}
if(canbeprocessed)
{
mark[i]=1;
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
}
}
}
//checking for unmarked processes
int deadlock=0;
for(i=0;i<np;i++)
if(mark[i]!=1)
deadlock=1;
if(deadlock)
printf("\n Deadlock detected");
else
printf("\n No Deadlock possible");
}

47
OUTPUT:
Enter the no of process: 4
Enter the no of resources: 5
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
00 0 0 0

Deadlock detected

RESULT:

48
EX. NO: 9 C PROGRAM TO IMPLEMENTTHREADING
DATE:

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in data types.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM CODING
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
void* doSomeThing(void *arg)
{
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);

for(i=0; i<(0xFFFFFFFF);i++);

printf("\n Job %d finished\n", counter);


return NULL;
}

49
int main(void)
{
int i = 0;
int err;
while(i < 2)
{
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL); if (err
!= 0)

printf ("\ncan't create thread :[%s]", strerror(err)); i++;


}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
return 0;
}

output:

Job 1 started

Job 2 started

Job 2 finished

Job 2 finished

RESULT:

50
EX. NO: 10 C PROGRAM TO IMPLEMENT PAGING TECHNIQUE
DATE:

AIM:

ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the critical section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variableto the
buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove item
from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result

PROGRAM :

#include<stdio.h>
int main()
{
int i,j,arr[100],pt[20],val,pgno,offset,phymem,fs,nf;
printf("\n Memory Management paging\n");
printf("enter the size of physical memory");
scanf("%d",&phymem);
for(i=20,j=0;i<phymem+20,j<phymem;i++,j++)
arr[i]=j;
printf("\n Enter size of frame or page");
scanf("%d",&fs);

51
nf=phymem/fs;
printf("No of frame available are\t%d",nf);
printf("\n Enter the page table");
for(i=0;i<nf;i++)
{

scanf("%d",&pt[i]);
}
printf("\n Enter the page no");
scanf("%d",&pgno);
printf("\n Enter the offset");
scanf("%d",&offset);
val=(fs*pt[pgno])+offset;
printf("the physical address is:%d\n",arr[val]);
}

Output:
Memory Management paging
enter the size of physical memory 5
Enter size of frame or page 4
No of frame available are 1
Enter the page table 6
Enter the page no 2
Enter the offset 3
the physical address is:0

RESULT:

52
EX. NO: 11 C PROGRAM TO IMPLEMENT MEMORY ALLOCATION
DATE: METHODS
(First Fit, Worst Fit, Best Fit)

AIM:

PROGRAM:

#include<stdio.h>
void firstFit(int blockSize[], int m, int processSize[], int n)
{
int i, j;
// Stores block id of the
// block allocated to a process
int allocation[n];

// Initially no block is assigned to any process


for(i = 0; i < n; i++)
{
allocation[i] = -1;
}

// pick each process and find suitable blocks


// according to its size ad assign to it
for (i = 0; i < n; i++) //here, n -> number of processes
{
for (j = 0; j < m; j++) //here, m -> number of blocks
{
if (blockSize[j] >= processSize[i])
{
// allocating block j to the ith process
allocation[i] = j;

53
// Reduce available memory in this block.
blockSize[j] -= processSize[i];

break; //go to the next process in the queue


}
}
}

printf("\nProcess No.\tProcess Size\tBlock no.\n");


for (int i = 0; i < n; i++)
{
printf(" %i\t\t\t", i+1);
printf("%i\t\t\t\t", processSize[i]);
if (allocation[i] != -1)
printf("%i", allocation[i] + 1);
else
printf("Not Allocated");
printf("\n");
}
}

// Driver code
int main()
{
int m; //number of blocks in the memory
int n; //number of processes in the input queue
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
m = sizeof(blockSize) / sizeof(blockSize[0]);
n = sizeof(processSize) / sizeof(processSize[0]);

firstFit(blockSize, m, processSize, n);


return 0 ;
}

54
OUTPUT:

Process No. Process Size Block no.


1 212 2
2 417 5
3 112 2
4 426 Not Allocated

RESULT:

55
EX. NO: 12.1 C PROGRAM TO IMPLEMENT PAGE REPLACEMENT
DATE: ALGORITHMS
(First in First Out)

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and in datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM :

#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)

56
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}

57
OUTPUT:

ENTER THE NUMBER OF PAGES: 20


ENTER THE PAGE NUMBER : 70120304230321201701
ENTER THE NUMBER OF FRAMES :3
ref string page frames
7 7 -1 -1
0 7 0 -1
1 7 0 1
2 2 0 1
0
3 2 3 1
0 2 3 0
4 4 3 0
2 4 2 0
3 4 2 3
0 0 2 3
3
2
1 0 1 3
2 0 1 2
0
1
7 7 1 2
0 7 0 2
1 7 0 1
Page Fault Is 15

RESULT:

58
EX. NO: 12.2 C PROGRAM TO IMPLEMENT PAGE REPLACEMENT
DATE: ALGORITHMS
(LRU)

AIM

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM CODING
#include<stdio.h>
int main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{

59
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
} }
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)

60
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
} } }
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
} }
}
printf("\nThe no of page faults is %d",c);
}

61
OUTPUT:
Enter no of pages:10
Enter the reference string:7 5 9 4 3 7 9 6 2 1
Enter no of frames:3
7
7 5
7 5 9
4 5 9
4 3 9
4 3 7
9 3 7
9 6 7
9 6 2
1 6 2

The no of page faults is 10

RESULT:

62
EX. NO: 13.1 C PROGRAM TO IMPLEMENT FILE ORGANIZATION
DATE: TECHNIQUES-SINGLE LEVEL

AIM

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution
PROGRAM :
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch;
char f[30];
[Link] = 0;
printf("\nEnter name of directory -- ");
scanf("%s", [Link]);
while(1)
{
printf("\n\n1. Create File\t2. Delete File\t3. Search File \n 4. Display Files\t5. Exit\nEnter
your choice -- ");
scanf("%d",&ch);

63
switch(ch)
{
case 1: printf("\nEnter the name of the file -- ");
scanf("%s",[Link][[Link]]);
[Link]++;
break;
case 2: printf("\nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<[Link];i++)
{ if(strcmp(f, [Link][i])==0)
{
printf("File %s is deleted ",f);
strcpy([Link][i],[Link][[Link]-1]); break; } }
if(i==[Link]) printf("File %s not found",f);
else
[Link]--;
break;
case 3: printf("\nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<[Link];i++)
{
if(strcmp(f, [Link][i])==0)
{
printf("File %s is found ", f);
} }
if(i==[Link])
printf("File %s not found",f);
break;
case 4: if([Link]==0)
printf("\nDirectory Empty");
else
{
printf("\nThe Files are -- ");
for(i=0;i<[Link];i++)

64
printf("\t%s",[Link][i]);
}
break;
default: exit(0);
} } }

OUTPUT:
Enter name of directory -- yagav
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit

Enter your choice -- 1


Enter the name of the file -- kid
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit

Enter your choice -- 2


Enter the name of the file -- kid
File kid is deleted
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit

Enter your choice -- 4


Directory Empty
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit

Enter your choice -- 5


RESULT:

65
EX. NO: 13.2 C PROGRAM TO IMPLEMENT FILE ORGANIZATION
DATE: TECHNIQUES-TWO LEVEL

AIM

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in datatypes.

Step 3: Enter the filename, index block.


Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM :

#include<string.h>
#include<stdlib.h>
#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];
dcnt=0;
while(1)
{

66
printf("\n\n1. Create Directory\t2. Create File\t3. Delete File");
printf("\n4. Search File\t\t5. Display\t6. Exit\tEnter 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].fname[dir[i].fcnt]);
printf("File created");
break;
}
if(i==dcnt)
printf("Directory %s not found",d);
break;
case 3: 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",f);
for(k=0;k<dir[i].fcnt;k++)
{

67
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("\nEnter name of the directory -- ");
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 jmp1;
} }
printf("File %s not found",f);
goto jmp1;
} }
printf("Directory %s not found",d);
jmp1: break;
case 5: if(dcnt==0)
printf("\nNo Directory's ");

68
else
{
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
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);
} } }

OUTPUT:

1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit Enter your choice -- 1

RESULT:

69
EX. NO: 13.3 C PROGRAM TO IMPLEMENT FILE ORGANIZATION
DATE: TECHNIQUES-HIERARCHIAL

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM
#include<stdio.h>
#include<graphics.h>
#include<string.h>
struct tree_element
{
char name[20];
int x, y, ftype, lx, rx, nc, level;
struct tree_element *link[5];
};
typedef struct tree_element node;
void main()
{
int gd=DETECT,gm;
node *root;
root=NULL;
create(&root,0,"root",0,639,320);
clrscr();

70
initgraph(&gd,&gm,"c:\tc\BGI");
display(root);
closegraph();
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i, gap;
if(*root==NULL)
{
(*root)=(node *)malloc(sizeof(node));
printf("Enter name of dir/file(under %s) : ",dname);
fflush(stdin);
gets((*root)->name);
printf("enter 1 for Dir/2 for file :");
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("No of sub directories/files(for %s):",(*root)->name); scanf("%d",&(*root)>nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)>link[i]),lev+1,(*root)>name,lx+gap*i,lx+gap*i+gap,
lx+gap*i+gap/2);
}
else

71
(*root)->nc=0;
}
}
display(node *root)
{
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root !=NULL)
{
for(i=0;i<root->nc;i++)
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root>y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
display(root->link[i]);
}
}

Output:

Enter name of dir/file (under root): ROOT


Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for ROOT):2
Enter name of dir/file (under root): USER 1
Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for ROOT):1
Enter name of dir/file (under USER 1): SUBDIR
Enter 1 for Dir/ 2 for File: 1

72
No of subdirectories /files (for SUBDIR):2
Enter name of dir/file (under USER 1): JAVA

Enter 1 for Dir/ 2 for File: 1


No of subdirectories /files (for JAVA):0
Enter name of dir/file (under SUBDIR): VB
Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for VB):0
Enter name of dir/file (under ROOT): USER 2
Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for USER 2):2
Enter name of dir/file (under ROOT): A
Enter 1 for Dir/ 2 for File: 2
Enter name of dir/file (under USER 2): SUBDIR 2
No of subdirectories /files (for SUBDIR 2):2
Enter name of dir/file (under SUBDIR 2): PPL
Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for PPL):2
Enter name of dir/file (under PPL): B
Enter 1 for Dir/ 2 for File: 2
Enter name of dir/file (under PPL): C
Enter 1 for Dir/ 2 for File: 2
Enter name of dir/file (under SUBDIR): AI
Enter 1 for Dir/ 2 for File: 1
No of subdirectories /files (for AI):2
Enter name of dir/file (under AI): D
Enter 1 for Dir/ 2 for File: 2
Enter name of dir/file (under AI): E
Enter 1 for Dir/ 2 for File: 2

73
ROOT

USER USER

SUBDIR A SUBDIR

JAVA VB PPL AI

D E
B C

RESULT:

74
EX. NO: 14.1 C PROGRAM TO IMPLEMENT FILE ALLOCATION
DATE: TECHNIQUE-INDEXED

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.

PROGRAM:
#include<stdio.h>
void main()
{
char a[10];
int i,ib,cib[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n index block:");
scanf("%d",&ib);
for(i=1;i<=5;i++)
{
printf("\n enter the child of index block %d:",i);
scanf("%d",&cib[i]);
}
printf("\n the list of files\t index block\n");
printf("%s\t\t %d",a,ib);

75
printf("\n the above file utiltization index block of child blocks followin\t");
printf("\n");
for(i=1;i<=5;i++)
{
printf("%d\t\t",cib[i])}printf("\n");
}

OUTPUT:

Enter the name:Testing


Index block:19
Enter the child of index block 1:9
Enter the child of index block 2:16
Enter the child of index block 3:1
Enter the child of index block 4:10

The list of files Testing


The above file utilization index block of child blocks following:

9 16 1 10 25

RESULT:

76
EX. NO: 14.2 C PROGRAM TO IMPLEMENT FILE ALLOCATION
DATE: TECHNIQUE-LINKED ALLOCATION

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,starting block ending block.
Step 4: Print the free block using loop.
Step 5:‟for‟ loop is created to print the file utilization of linked type of entered type .
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM

#include<stdio.h>
void main()
{
char a[10];
int i,sb,eb,fb1[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n Enter the starting block:");
scanf("%d",&sb);
printf("Enter the ending Block:");
scanf("%d",&eb);
for(i=0;i<5;i++)
{
printf("Enter the free block %d",i+1);
scanf("%d",&fb1[i]);

77
}
printf("\n File name \t Starting block \t Ending block \n");
printf("%s \t\t %d\t\t %d",a,sb,eb);
printf("\n %s File Utilization of Linked type of following blocks:",a);
printf("\n %d->",sb);
for(i=0;i<5;i++)
{
printf("%d->",fb1[i]);
}
printf("%d\n",eb);
}

OUTPUT:
Enter the file name :binary Enter
the starting block:19
Enter the ending
block:25 Enter the free
block:1:12 Enter the free
block:2:34 Enter the free
block:3:21 Enter the free
block:4:18 Enter the free
block:5:35

ending
File name starting block block
Binary 19 25

Binary file utilization of linked type of the following


blocks: 19 12 34 21 18 35 25

RESULT:

78
EX. NO: 14.3 C PROGRAM TO IMPLEMENT FILE ALLOCATION
DATE: TECHNIQUE- SEQUENTIAL ALLOCATION

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,starting block ending block.
Step 4: Print the free block using loop.
Step 5:‟for‟ loop is created to print the file utilization of linked type of entered type .
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM:
#include < stdio.h>
#include<conio.h>
void main()
{
int f[50], i, st, len, j, c, k, count = 0;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Files Allocated are : \n");
x: count=0;
printf(“Enter starting block and length of files: ”);
scanf("%d%d", &st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0)
count++;
if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[j]==0)
{

79
f[j]=1;
printf("%d\t%d\n",j,f[j]);
}
if(j!=(st+len-1))
printf(” The file is allocated to disk\n");
}
else
printf(” The file is not allocated \n");
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit();
getch();
}
OUTPUT:
Files allocated are:
Enter starting block and length of files: 17 4
17 1
18 1
19 1
20 1
The file is allocated to disk
Do you want to enter more file (Yes-1 / No-0) 1
Enter starting block and length of files: 21 3
21 1
22 1
23 1
The file is allocated to disk
Do you want to enter more file (Yes-1 / No-0) 0
RESULT:

80
EX. NO: 15.1 C PROGRAM TO IMPLEMENT DISK SCHEDULING
DATE: ALGORITHM-FCFS

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2: Let request array represents an array storing indexes of tracks that have been requested in
ascending order of the time arrival.’head’ is the p
osition of disk head.
Step 3: Let us one by one take the tracks in default order and calculate the absolute distance of the
track from the head.
Step 4: Increment the total seek count with this distance.
Step 5: Currently serviced track position now becomes the new head position.
Step 6: Go to Step3 until all tracks in request array have not been serviced.
Step 7: Stop the execution

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);

81
// logic for FCFS disk scheduling

for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}

printf("Total head moment is %d",TotalHeadMoment);


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:

82
EX. NO: 15.2 C PROGRAM TO IMPLEMENT DISK SCHEDULING
DATE: ALGORITHM-SSTF

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2: Let request array represents an array storing indexes of tracks that have been requested in
ascending order of the time arrival. ’head’ is the position of disk head.
Step 3: Find the positive distance of all tracks in request array from head.
Step 4: Find a track from requested array which has not been accessed/ serviced yet and has
minimum distance from head.
Step 5: Increment the total seek count with this distance.
Step 6: Currently serviced track position now becomes the new head position.
Step 7: Go to Step3 until all tracks in request array have not been serviced.
Step 8: Stop the execution

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

83
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
} }
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 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
Enter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
50
Total head movement is 236

RESULT:

84
EX. NO: 15.2 C PROGRAM TO IMPLEMENT DISK SCHEDULING
DATE: ALGORITHM-SCANDISK

AIM:

ALGORITHM:
Step 1: Start the Program
Step 2: Let request array represents an array storing indexes of tracks that have been requested in
ascending order of the time arrival. ’head’ is the position of disk head.
Step 3: Let direction represents whether the head moving towards left or right.
Step 4: In the direction in which head is moving service all tracks one by one.
Step 5: Calculate the absolute distance of the track from the head.
Step 6: Increment the total seek count with this distance.
Step 7: Currently serviced track position now becomes the new head position.
Step 8: Go to Step3 until we reach at one of the ends of the disk.
Step 9: If we reach at the end of the disk reverse the direction and go to step2 until all tracks in
request array have not been serviced.
Step 10: Stop the execution

PROGRAM:
#include <stdio.h>
#include <math.h>
int main()
{
int queue[20], n, head, i, j, k, seek = 0, max, diff, temp, queue1[20],
queue2[20], temp1 = 0, temp2 = 0;
float avg;
printf("Enter the max range of disk\n");
scanf("%d", &max);
printf("Enter the initial head position\n");
scanf("%d", &head);

85
printf("Enter the size of queue request\n");
scanf("%d", &n);
printf("Enter the queue of disk positions to be read\n");

for (i = 1; i <= n; i++)


{
scanf("%d", &temp);
if (temp >= head)
{
queue1[temp1] = temp;
temp1++;
}
else
{
queue2[temp2] = temp;
temp2++;
}
}
for (i = 0; i < temp1 - 1; i++)
{
for (j = i + 1; j < temp1; j++)
{
if (queue1[i] > queue1[j])
{
temp = queue1[i];
queue1[i] = queue1[j];
queue1[j] = temp;
}
}
}
for (i = 0; i < temp2 - 1; i++)
{
for (j = i + 1; j < temp2; j++)
{

86
if (queue2[i] < queue2[j])
{
temp = queue2[i];
queue2[i] = queue2[j];
queue2[j] = temp;
}
}
}
for (i = 1, j = 0; j < temp1; i++, j++)
queue[i] = queue1[j];
queue[i] = max;
for (i = temp1 + 2, j = 0; j < temp2; i++, j++)
queue[i] = queue2[j];
queue[i] = 0;
queue[0] = head;
for (j = 0; j <= n + 1; j++)
{
diff = abs(queue[j + 1] - queue[j]);
seek += diff;
printf("Disk head moves from %d to %d with seek %d\n", queue[j],
queue[j + 1], diff);
}
printf("Total seek time is %d\n", seek);
avg = seek / (float)n;
printf("Average seek time is %f\n", avg);
return 0;
}

87
OUTPUT:
Enter the max range of disk
5
Enter the initial head position
50
Enter the size of queue request
4
Enter the queue of disk positions to be read
23
56
78
12
Disk head moves from 50 to 56 with seek 6
Disk head moves from 56 to 78 with seek 22
Disk head moves from 78 to 5 with seek 73
Disk head moves from 5 to 23 with seek 18
Disk head moves from 23 to 12 with seek 11
Disk head moves from 12 to 0 with seek 12
Total seek time is 142
Average seek time is 35.500000

RESULT:

88

You might also like