Sunteți pe pagina 1din 40

EX. NO. : 01.

DATE :
BASIC COMMANDS IN LINUX

AIM: To study the basic commands in Linux.

COMMANDS

1. TASK : To display the system date and time.


COMMAND : date.
SYNTAX : date.
EXPLANATION : This command displays the current system date and time
on the screen.
OUTPUT : Tue Jun 19 11:37:17 GMT 2007.

2. TASK : To display the current month.


COMMAND : date.
SYNTAX : date +%m.
EXPLANATION : This command displays the current month on the
screen.
OUTPUT : 06.

3. TASK : To display the name of the current month.


COMMAND : date.
SYNTAX : date +%h.
EXPLANATION : This command displays the name of the current month
on the screen.
OUTPUT : Jun.

4. TASK : To display the current system date.


COMMAND : date.
SYNTAX : date +%d.
EXPLANATION : This command displays the current system date on the
screen.
OUTPUT : 19.

5. TASK : To display the current system date (year).


COMMAND : date.
SYNTAX : date +%y.
EXPLANATION : This command displays the current year on the screen.
OUTPUT : 07.

6. TASK : To display the current system time.


COMMAND : date.
SYNTAX : date +%H.
EXPLANATION : This command displays the current system time (in
hours) on the screen.
OUTPUT : 11.

CS 405 Operating System Lab 1


7. TASK : To display the current system time.
COMMAND : date.
SYNTAX : date +%M.
EXPLANATION : This command displays the current system time (in
minutes) on the screen.
OUTPUT : 43.

8. TASK : To display the current system time.


COMMAND : date.
SYNTAX : date +%S.
EXPLANATION : This command displays the current system time (in
seconds) on the screen.
OUTPUT : 15.

9. TASK : To display the calendar of the current month.


COMMAND : calendar.
SYNTAX : cal.
EXPLANATION : This command displays the calendar of the current
month on the screen.
OUTPUT : Jun 07

S M T W T F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

10. TASK : To display user-defined message.


COMMAND : echo.
SYNTAX : echo “message”.
EXPLANATION : This command displays on the screen the argument of
the echo command.
OUTPUT : echo “OS”.

11. TASK : To display the details of all users.


COMMAND : who.
SYNTAX : who.
EXPLANATION : This command lists the information about all the users
who have logged on to that system.
OUTPUT :

CS 405 Operating System Lab 2


12. TASK : To display the user detail.
COMMAND : who.
SYNTAX : whoami.
EXPLANATION : This command displays information about the current
user of the system on the screen.
OUTPUT : root.

13. TASK : To create a directory.


COMMAND : make directory.
SYNTAX : mkdir.
EXPLANATION : This command is used to create a new directory with the
Specified name.
EXAMPLE : mkdir student.
OUTPUT : The directory “student” is created.

14. TASK : To change directory.


COMMAND : change directory.
SYNTAX : cd directory name.
EXPLANATION : This command is used to switch from one directory to
another.
EXAMPLE : cd staff.
OUTPUT : The directory “staff” is switched onto.

15. TASK : To delete a directory.


COMMAND : remove directory.
SYNTAX : rmdir directory name
EXPLANATION : This command is used to delete the specified directory.
EXAMPLE : rmdir student.
OUTPUT : The “student” directory is deleted.

16. TASK : To come out of a sub-directory.


COMMAND : change directory.
SYNTAX : cd ..
EXPLANATION : This command helps in switching to the main directory.
OUTPUT :

17. TASK : To list all the files and directories.


COMMAND : list.
SYNTAX : ls.
EXPLANATION : This command displays all the files and directories of
the system.
OUTPUT :

18. TASK : To create a file.


COMMAND : cat.
SYNTAX : cat> file name.
EXPLANATION : This command leads to the creation of a new file with
the specified file name and contents.

CS 405 Operating System Lab 3


EXAMPLE : cat> wind.
OUTPUT : A null file called “wind” is created.

19. TASK : To view a file.


COMMAND : cat.
SYNTAX : cat file name.
EXPLANATION : This command displays the contents of the specified file.
EXAMPLE : cat wind.
OUTPUT : Contents of the file called “wind” will be displayed on
the screen.

20. TASK : To copy a file.


COMMAND : copy.
SYNTAX : cp sourcefile destinationfile.
EXPLANATION : This command produces a copy of the source file and is
stored in the specified destination file by overwriting its
previous contents.
EXAMPLE : cp sun moon.
OUTPUT : The contents of “sun” file will be copied to the “moon”
file.

21. TASK : To move a file.


COMMAND : move.
SYNTAX : mv sourcefile destinationfile.
EXPLANATION : After moving the contents of the source file into
destination file, the source file is deleted.
EXAMPLE : mv sun moon.
OUTPUT : After copying contents from the “sun” file to “moon”
file, The “sun” file is deleted.

22. TASK : To display / cut a column from a file.


COMMAND : cut.
SYNTAX : cut –c no. file name.
EXPLANATION : This command displays the characters of a particular
column in the specified file.
EXAMPLE : cut –c3 moon.
OUTPUT : Those characters occurring in the 3rd column of the file
called “moon” are displayed.

23. TASK : To delete a file.


COMMAND : remove.
SYNTAX : rm file name.
EXPLANATION : This command deletes the specified file from the
directory.
EXAMPLE : rm sun.
OUTPUT : The file called “sun” will be deleted.

CS 405 Operating System Lab 4


24. TASK : To retrieve a part of a file.
COMMAND : head.
SYNTAX : head -no. of rows file name.
EXPLANATION : This command displays the specified no. of rows form
the top of the specified file.
EXAMPLE : head -1 sun.
OUTPUT : The first row of the file called “sun” is displayed.

25. TASK : To retrieve a file.


COMMAND : tail.
SYNTAX : tail -no. of rows file name.
EXPLANATION : This command displays the specified no. of rows form
the bottom of the specified file.
EXAMPLE : tail -1 moon.
OUTPUT : The last row of the file called “moon” is displayed.
26. TASK : To sort the contents of a file.
COMMAND : sort.
SYNTAX : sort file name.
EXPLANATION : This command helps in sorting the contents of a file in
Ascending order.
EXAMPLE : sort win.
OUTPUT : The contents of the file “win” are displayed on the
screen in a sorted order.

27. TASK : To display the no. of characters in a file.


COMMAND : word count.
SYNTAX : wc file name.
EXPLANATION : This command displays on the screen the no. of rows,
words, And the sum of no. of characters and words.
EXAMPLE : wc ball.
OUTPUT : The no. of rows, words, and no. of characters present in
the file “ball” are displayed.

28. TASK : To display the calendar of a year.


COMMAND : cal.
SYNTAX : cal year.
EXPLANATION : This command displays on the screen the calendar of the
specified year.
EXAMPLE : cal 2007.
OUTPUT : The calendar of the year 2007 will be displayed.

CS 405 Operating System Lab 5


RESULT:

Thus the program basic commands in Linux successfully verified.

CS 405 Operating System Lab 6


EX. NO. : 02.
DATE :
System Calls of UNIX Operating System

Aim

Write programs using the following system calls of UNIX operating system: fork,
exec, getpid, exit, wait, close, stat, opendir, readdir.

Algorithm

Step 1: Declare the integer value pid1.

Step 2: Get the getpid value from system using printf ststement.

Step 3: Assign the pid1 value to fork function.

Step 4: The fork () function creates a new process. The new process (child process) is

an exact copy of the calling process (parent process)

Step 5: If pid1 is equal to zero then assign getpid() to pid1 and display “ I am always

executed by child process..Child…”

Step 6: otherwise display the “ I am the parent”

Step 7: End the process

CS 405 Operating System Lab 7


PROGRAM

#include<stdio.h>
main()
{
int pid1;
printf("I am the main process:%u\n",getpid());
printf("clear(garbage value):%u\n",pid1);
pid1=fork();
printf("current process if:%u\n",pid1);
printf("present pid value%u\n",pid1);
if(pid1==0)
{
printf("I am the child:%u%u\n",pid1,getpid());
pid1=getpid();
if(pid1==getpid())
printf("\n I am always executed by child process...child...");
}
else
{
printf("\n I am the parent:%u%u\n",pid1,getpid());
if(pid1==getpid())
printf("\n I am always executed by child process...parent...");
}
}

CS 405 Operating System Lab 8


OUTPUT:

[osb32@localhost osb32]$ cc ex1a.c


[osb32@localhost osb32]$ ./a.out
I am the main process:13137
clear(garbage value):1073828704
current process if:0
present pid value0
I am the child:013138

I am always executed by child process...child...current process if:13138


present pid value13138

I am the parent:1313813137
[osb32@localhost osb32]$

RESULT:

Thus the program to implement system calls of UNIX operating system: fork,
exec, getpid, exit, wait, close, stat, opendir, readdir. was executed and verified
successfully.

CS 405 Operating System Lab 9


EX.NO: 03.
DATE:
FIRST COME FIRST SERVE ALGORITHM

AIM:

To write a program to implement First come first serve (FCFS) algorithm.

Algorithm

Step 1: Start the process

Step 2: Declare the array size

Step 3: Get the number of processes to be inserted

Step 4: Get the value

Step 5: Start with the first process from it’s initial position let other process to be in

queue

Step 6: Calculate the total number of burst time

Step 7: Display the values

Step 8: Stop the process

CS 405 Operating System Lab 10


PROGRAM

#include<stdio.h>
main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float att=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");
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=awt+w[i];
att=att+t[i];
}
awt =awt/n;
att=att/n;
printf("\n\tprocess\twaiting time\tturn arround time\n");
for(i=0;i<n;i++)

CS 405 Operating System Lab 11


{
printf("\tp%d\t\t%d\t\t%d\n",i,w[i],t[i]);
}
printf("the average waiting time is %f\n",awt);
printf("the average turn around time is %f\n",att);
}

CS 405 Operating System Lab 12


OUTPUT

Enter the number of process 4


Enter the burst times
4 9 8 3
Enter the arrival times
0 2 4 3
Process waiting time turnaround time
p0 0 4
p1 2 11
p2 9 17
p3 18 21
The average waiting time is 7.250000
The average turnaround time is 13.250000

RESULT:

Thus the program to implement the First Come First Serve scheduling algorithm
executed successfully.

CS 405 Operating System Lab 13


EX.NO: 0 4. SHORTEST JOB FIRST SCHEDULING
DATE: ALGORITHM

Aim

To implement the shortest job first scheduling algorithm

Algorithm

Step 1: Start the process

Step 2: Declare the array size

Step 3: Get the number of elements to be inserted

Step 4: Select the process which have shortest burst will execute first

Step 5: If two process have same burst length then FCFS scheduling algorithm used

Step 6: Make the average waiting the length of next process

Step 7: Start with the first process from it’s selection as above and let other process to
be in queue

Step 8: Calculate the total number of burst time

Step 9: Display the values

Step 10: Stop the process

CS 405 Operating System Lab 14


PROGRAM

#include<stdio.h>
int main()
{

int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10],i;

float att=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]);
p[i]=i;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
temp1=p[i];
b[i]=b[j];
p[i]=p[j];
b[j]=temp;
p[j]=temp1;
}

CS 405 Operating System Lab 15


}
}
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;
printf("\n\t process \t waiting time \t turnaround 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 waiting time is %f\n",awt);
printf("the average turnaround time is %f\n",att);
return 1;
}

CS 405 Operating System Lab 16


OUTPUT

Enter the number of process 5


Enter the burst times
2 4 5 6 8

Process waiting time turnaround time


p[0] 0 2
p[1] 2 6
p[2] 6 11
p[3] 11 17
p[4] 17 25
The average waiting time is 7.200000
The average turnaround time is 12.200000

RESULT:

Thus the program to implement the shortest job first scheduling algorithm
executed successfully.

CS 405 Operating System Lab 17


EX.NO: 05.
ROUND ROBIN SCHEDULING ALGORITHM
DATE:

Aim

To write a program to implement the round robin scheduling algorithm

Algorithm

Step1: Start the process

Step2: Declare the array size

Step3: Get the number of elements to be inserted

Step4: Get the value

Step5: Set the time sharing system with preemption

Step6: Define quantum is defined from 10 to 100ms

Step7: Declare the queue as a circular

Step8: Make the CPU scheduler goes around the ready queue allocating CPU to each
process for the time interval specified

Step9: Make the CPU scheduler picks the first process and sets time to interrupt after
quantum expired dispatches the process

Step10: If the process have burst less than the time quantum than the process release
the CPU

Step11: If the process have bust greater then time quantum then time will go off and
cause interrupt to OS and the process put into the tail of ready queue and the
schedule select next process

Step12: Display the results

Step13: Stop the process

CS 405 Operating System Lab 18


PROGRAM
#include<stdio.h>
int ttime,i,j,temp;
main()
{
int pname[10],btime[10],pname2[10],btime2[10];
int n,x,z;
printf("Enter the no. of process:");
scanf("%d",&n);
printf("Enter the process name and burst time for the process\n");
for(i=0;i<n;i++)
{
printf("Enter the process name:");
scanf("%d",&pname2[i]);
printf("Enter burst time for the process %d:",pname2[i]);
scanf("%d",&btime2[i]);
}
printf("PROCESS NAME \t\t BURST TIME\n");
for(i=0;i<n;i++)
printf("%d\t\t\t %d\n",pname2[i],btime2[i]);
z=1;
while(z==1)
{
ttime=0;
for(i=0;i<n;i++)
{
pname[i]=pname2[i];
btime[i]=btime2[i];
}
printf ("PRESS 1.ROUND ROBIN 2.EXIT\n");
scanf("%d",&x);
switch(x)

CS 405 Operating System Lab 19


{
case 1:
rrobin(pname,btime,n);
break;
case 2:
exit(0);
break;
default:
printf("Invalid option");
break;
}
printf("\n\n If you want to continue press 1:");
scanf("%d",&z);
}
}

rrobin(int pname[],int btime[],int n)


{
int tslice;
j=0;
printf("\n\t ROUND ROBIN SCHEDULING \n\n");
printf("Enter the time slice:\n");
scanf("%d",&tslice);
printf("PROCESS NAME \t REMAINING TIME\t TOTAL TIME");
while(j<n)
{
for(i=0;i<n;i++)
{
if(btime[i]>0)
{
if(btime[i]>=tslice)
{

CS 405 Operating System Lab 20


ttime+=tslice;
btime[i]=btime[i]-tslice;
printf("\n%d\t\t %d \t\t %d",pname[i],btime[i],ttime);
if(btime[i]==0)
j++;
}
else
{
ttime+=btime[i];
btime[i]=0;
printf("\n%d\t\t %d \t\t %d",pname[i],btime[i],ttime);
}
}
}
}
}

CS 405 Operating System Lab 21


OUTPUT

Enter the no. of process: 4


Enter the process name and burst time for the process
Enter the process name: 1
Enter burst time for the process 1: 8
Enter the process name: 2
Enter burst time for the process 2: 3
Enter the process name: 3
Enter burst time for the process 3: 6
Enter the process name: 4
Enter burst time for the process 4: 1

PROCESS NAME BURST TIME


1 8
2 3
3 6
4 1

PRESS 1.ROUND ROBIN 2.EXIT


1
ROUND ROBIN SCHEDULING

Enter the time slice:


2

CS 405 Operating System Lab 22


PROCESS NAME REMAINING TIME TOTAL TIME
1 6 2
2 1 4
3 4 6
4 0 7
1 4 9
2 0 10
3 2 12
1 2 14
3 0 16

RESULT:

Thus the program to implement the round robin scheduling algorithm executed
successfully.

CS 405 Operating System Lab 23


EX.NO: 06.
PRODUCER – CONSUMER PROBLEM USING
DATE: SEMAPHORES

Aim:
To write a program to implement producer consumer problem using semaphore
variable.

Algorithm:

Step 1: Declare required variables and assign required values for variables.
Step 2: Declare producer, consumer, wait and signal functions.
Step 3: Producer function:
The Producer can produce any number of items still he/she has space to store
the item when he/she gets the signal.

Step 4: Consumer function:


The Consumer can consume any number of items still items available
when
he/she gets the signal.

Step 5: Signal function:


Increments the given value by one.

Step 6: Wait function:


Decrements the given value by one.

CS 405 Operating System Lab 24


PROGRAM

#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("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1)
{
printf("\nENTER YOUR CHOICE\n");
scanf("%d",&n);
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;

CS 405 Operating System Lab 25


} }
}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return(++s);
}
void producer()
{
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=signal(empty);
printf("\n consumer consumes item%d",x);
x--;
mutex=signal(mutex);
}

CS 405 Operating System Lab 26


OUTPUT

1.PRODUCER
2.CONSUMER
3.EXIT

ENTER YOUR CHOICE


1
producer produces the item1
ENTER YOUR CHOICE
1
producer produces the item2
ENTER YOUR CHOICE
1
producer produces the item3
ENTER YOUR CHOICE
1
BUFFER IS FULL
ENTER YOUR CHOICE
2
consumer consumes item3
ENTER YOUR CHOICE
2
consumer consumes item2
ENTER YOUR CHOICE
2
consumer consumes item1
ENTER YOUR CHOICE
2
BUFFER IS EMPTY
ENTER YOUR CHOICE
3

RESULT:

Thus the program to implement producer consumer problem was created and
executed successfully.

CS 405 Operating System Lab 27


EX.NO: 07.
SEGMENTATION
DATE:

Aim:
To write a program to implement memory management scheme using
segmentation.

Algorithm:

Step 1: Read the base address, number of segments size of each segment and
memory limit.

Step 2: If memory address is less than base address display “Invalid memory
limit”.

Step 3: Create a segment table with the segment memory and segment
address and display it.

Step 4: Read the segment number and displacement.

Step 5: If the segment number and displacement is valid compute the real
address and display the same.

CS 405 Operating System Lab 28


PROGRAM

#include<stdio.h>
main()
{
int n,p,b[10],i,s,la,l[10];
char a[10];
printf("\n Enter the no.of segments:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter the limit:");
scanf("%d",&l[i]);
printf("\n Enter the base:");
scanf("%d",&b[i]);
}
printf("\n Index \t limit \t base \n");
for(i=1;i<=n;i++)
printf("%d \t %d \t %d \n",i,l[i],b[i]);
printf("\n Enter the no.of process:");
scanf("%d",&p);
for(i=1;i<=p;i++)
{
printf("\n Enter the process name:");
scanf("%s",&a);
printf("\n Enter the segment number:");
scanf("%d",&s);
printf("\n Enter the logical address:");
scanf("%d",&la);
if(s<=n)
{
if(la<=l[s])
printf("\n The process %s is filled into the segment %d",a,s);

CS 405 Operating System Lab 29


else
{
printf("\n Segmentation fault");
exit(0);
}
}
}
}

CS 405 Operating System Lab 30


OUTPUT:

[osb32@localhost osb32]$ ./a.out

Enter the no.of segments:4

Enter the limit:1000

Enter the base:100

Enter the limit:2000

Enter the base:300

Enter the limit:1500

Enter the base:200

Enter the limit:3000

Enter the base:250

Index limit base


1 1000 100
2 2000 300
3 1500 200
4 3000 250

Enter the no.of process:4

Enter the process name:p1

Enter the segment number:2

Enter the logical address:1234

The process p1 is filled into the segment 2


Enter the process name:p2

Enter the segment number:3

Enter the logical address:1435

CS 405 Operating System Lab 31


The process p2 is filled into the segment 3
Enter the process name:p3

Enter the segment number:3

Enter the logical address:1455

The process p3 is filled into the segment 3


Enter the process name:p4

Enter the segment number:3

Enter the logical address:1501

Segmentation fault[osb32@localhost osb32]$

RESULT:
Thus the program to implement memory management scheme-Segmentation was
created and executed successfully.

CS 405 Operating System Lab 32


EX.NO: 8 MEMORY MANAGEMENT SCHEME-II -
DATE: PAGING

Aim:
To write a program to implement memory management scheme using paging.

Algorithm:

Step 1: Enter the size of physical memory.

Step 2: Enter the frame size.

Step 3: Determine the number of frame available by dividing the physical memory by
framesize.

Step 4: Read the pagetable.

Step 5: Read the pagetable and offset.

Step 6: Calculate the physical address using

val= [framesize * pagetable [pageno] + offset]

Step 7: Display the physical address.

CS 405 Operating System Lab 33


PROGRAM:

#include<stdio.h>
main()
{
int i,arr[100],pagetable[20],val,pageno,offset,phymem;
int framesize,noframes;
printf("\n Enter the size of physical memory");
scanf("%d",&phymem);
for(i=0;i<phymem;i++)
arr[i]=i;
printf("\n Enter the size of frame or page:");
scanf("%d",&framesize);
noframes=phymem/framesize;
printf("\n The no.of frames available are %d",noframes);
printf("\n Enter the pagetable \n");
for(i=0;i<noframes;i++)
scanf("%d",&pagetable[i]);
printf("\n Enter the pageno.");
scanf("%d",&pageno);
printf("\n Enter the offset");
scanf("%d",&offset);
val=(framesize*pagetable[pageno])+offset;
printf("\n The physical + offset address is %d \n",arr[val]);
}

CS 405 Operating System Lab 34


OUTPUT

[osb32@localhost osb32]$ cc ex9a.c


[osb32@localhost osb32]$ ./a.out

Enter the size of physical memory 10000


Segmentation fault
[osb32@localhost osb32]$ ./a.out

Enter the size of physical memory 1000


Segmentation fault
[osb32@localhost osb32]$ ./a.out

Enter the size of physical memory 100

Enter the size of frame or page:20

The no.of frames available are 5


Enter the pagetable
1
2
3
4
5

Enter the pageno.4

Enter the offset 3

The physical + offset address is 5


[osb32@localhost osb32]$

RESULT:
Thus the program to implement memory management scheme-Paging was
created and executed successfully.

CS 405 Operating System Lab 35


EX.NO: 09 MEMORY MANAGEMENT SCHEME-I - FIRST
DATE: FIT

Aim:
To write a program to implement memory management scheme-I First fit.

Algorithm:

Step 1: Declare two structures process and size.

Step 2: Get the number of blocks from the user.

Step 3: Allocate the size for each block.

Step 4: Get the number of process and size of the process from the user.

Step 5: Blocks will be allocated in First come first serve manner.

CS 405 Operating System Lab 36


PROGRAM

#include<stdio.h>
struct process
{
int ps,flag;
}p[5];
struct hole
{
int size,alloc;
}h[5];
int main()
{
int i=0,j=0,n=0,np=0;
printf("\n\t\t First Fit \n\n");
printf("\n Enter the no.of holes");
scanf("%d",&n);
printf("\n\t Enter the size for %d holes",n);
for(i=0;i<n;i++)
{
printf("\n\t Enter the size for %d holes",i);
scanf("%d",&h[i].size);
}
printf("\n\t Enter the no.of process");
scanf("%d",&np);
printf("\n\t\t Enter the size of %d process",np);
printf("\n");
for(i=0;i<np;i++)
{
printf("\n Enter the size of the process %d",i);
scanf("%d",&p[i].ps);
}
printf("\n Allocation of holes using first fit is as follows\n");

CS 405 Operating System Lab 37


printf("\n Process \t Process size \t Holes");
for(i=0;i<np;i++)
for(j=0;j<n;j++)
if(p[i].flag!=1)
if(p[i].ps<h[j].size)
if(!h[j].alloc)
{
p[i].flag=1;
h[j].alloc=1;
printf("\n %d \t\t %d \t\t %d",i,p[i].ps,h[j].size);
}
for(i=0;i<np;i++)
{
if(p[i].flag==0)
printf("\n Sorry! Process %d must wait as there is no memory \n",i);
}
}

CS 405 Operating System Lab 38


OUTPUT

[osb32@localhost osb32]$ ./a.out

First Fit

Enter the no.of holes 2

Enter the size for 2 holes


Enter the size for 0 holes 100

Enter the size for 1 holes 200

Enter the no.of process 2

Enter the size of 2 processes

Enter the size of the process 0 50

Enter the size of the process 1 150

Allocation of holes using first fit is as follows

Process Processsize Holes


0 50 100
1 150 200
[osb32@localhost osb32]$ ./a.out

First Fit

Enter the no.of holes 2

Enter the size for 2 holes


Enter the size for 0 holes 100

Enter the size for 1 holes 200

Enter the no.of process 2

Enter the size of 2 processes

Enter the size of the process 0 150

Enter the size of the process 1 250

Allocation of holes using first fit is as follows

CS 405 Operating System Lab 39


Process Processsize Holes
0 150 200

Sorry! Process 1 must wait as there is no memory

[osb32@localhost osb32]$

RESULT:

Thus the program to implement first fit memory management scheme was
created and executed successfully.

CS 405 Operating System Lab 40

S-ar putea să vă placă și