0% found this document useful (0 votes)
171 views34 pages

Os Lab Manual R20

Uploaded by

pradeepdoddi61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views34 pages

Os Lab Manual R20

Uploaded by

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

Operating Systems & Compiler Design using C Laboratory

List of Experiments

Part-A

1 Simulate the following CPU scheduling algorithms a) Round Robin b) Shortest Job First c) Priority

a) ROUND ROBIN:

DESCRIPTION:
· Round Robin is the preemptive process scheduling algorithm.
· Each process is provided a fix time to execute, it is called a quantum.
· Once a process is executed for a given time period, it is preempted and other process executes for a
given time period.
· Context switching is used to save states of preempted processes.
PROGRAM:

/* C Program to implement Round Robin CPU Scheduling Algorithm */

#include<stdio.h>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
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];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|TurnaroundTime|Waiting Time\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(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
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 ProcessNumber 1:0
9
Enter Arrival Time and Burst Time for Process ProcessNumber 2:1
5
Enter Arrival Time and Burst Time for Process ProcessNumber 3:2
3
Enter Arrival Time and Burst Time for Process ProcessNumber 4:3
4
Enter Time Quantum: 5
Process Turnaround Time Waiting Time
P[2] 9 4
P[3] 11 8
P[4] 14 10
P[1] 21 12

Average Waiting Time= 8.500000


Avg Turnaround Time = 13.70000

b) SJF:

DESCRIPTION:
· This is also known as shortest job first, or SJF
· This is a non-preemptive, pre-emptive scheduling algorithm.
· Best approach to minimize waiting time.
· Easy to implement in Batch systems where required CPU time is known in advance.
· Impossible to implement in interactive systems where required CPU time is not known.
· The processer should know in advance how much time process will take.
PROGRAM:

/* C Program to implement SJF CPU Scheduling Algorithm */

#include<stdio.h>
void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
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];
}
avg_wt=(float)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\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n;
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}

OUTPUT:

Enter number of process: 4


Enter Burst Time:
P1:4
P2:8
P3:3
P4:7
Process Burst Time Waiting Time Turnaround Time
P3 3 0 3
P1 4 3 7
P4 7 7 14
P2 8 14 22
Average Waiting Time=6.000000
Average Turnaround Time=11.500000

EX-2
Multiprogramming-Memory management- Implementation of fork (), wait (), exec() and exit(), System
calls?
FORK():

Fork system call use for creates a new process, which is called child process, which runs concurrently
with process (which process called system call fork) and this process is called parent process. After a
new child process created, both processes will execute the next instruction following the fork() system
call. A child process uses the same pc(program counter), same CPU registers, same open files which use
in the parent process.

EXEC():

The exec family of functions replaces the current running process with a new process. It can be used to
run a C program by using another C program. It comes under the header file unistd.h. There are many
members in the exec family which are shown below with examples.

· execvp : Using this command, the created child process does not have to run the same program as the
parent process does. The exec type system calls allow a process to run any program files, which include
a binary executable or a shell script .

Syntax:

int execvp (const char *file, char *const argv[]);

file: points to the file name associated with the file being executed.
argv: is a null terminated array of character pointers.

· execv : This is very similar to execvp() function in terms of syntax as well. The syntax of execv() is as
shown below:

Syntax:

int execv(const char *path, char *const argv[]);

path: should point to the path of the file being executed.


argv[]: is a null terminated array of character pointers.
· execlp and execl : These two also serve the same purpose but the syntax of of them are a bit different
which is as shown below:

Syntax:

int execlp(const char *file, const char *arg,.../* (char *) NULL */);

int execl(const char *path, const char *arg,.../* (char *) NULL */);

· execvpe and execle : These two also serve the same purpose but the syntax of them are a bit different
from all the above members of exec family. The synatxes of both of them are shown below :
Syntax:

int execvpe(const char *file, char *const argv[],char *const envp[]);

Syntax:

int execle(const char *path, const char *arg, .../*, (char *) NULL,

char * const envp[] */);

WAIT() :

A call to wait() blocks the calling process until one of its child processes exits or a signal is received. After
child process terminates, parent continues its execution after wait system call instruction.
Child process may terminate due to any of these:

· It calls exit();

· It returns (an int) from main

· It receives a signal (from the OS or another process) whose default action is to terminate.

EXIT():

It terminates the calling process without executing the rest code which is after the exit()
function.

FORK():

PROGRAM:
/* C Program to implement Fork() system calls */

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

void forkexample()

if (fork() == 0)

printf("Hello from Child!\n");

else

printf("Hello from Parent!\n");

int main()

forkexample();

return 0;

OUTPUT:

Hello from Child!


Hello from Parent!
EXEC():
/* C Program to implement Exec() system calls */

PROGRAM:

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <errno.h>

#include <sys/wait.h>

int main()

pid_t

pid;

int ret = 1;

int status;

pid = fork();

if (pid == -1)

printf("can't fork, error occured\n");

exit(EXIT_FAILURE);
}

else if (pid == 0)

printf("child process, pid = %u\n",getpid());

execv("ls",argv_list);

exit(0);

else{

printf("parent process, pid = %u\n",getppid());

if (waitpid(pid, &status, 0) > 0)

if (WIFEXITED(status) && !WEXITSTATUS(status))

printf("program execution successfull\n");

else if (WIFEXITED(status) && WEXITSTATUS(status))

if (WEXITSTATUS(status) == 127)

printf("execv failed\n");

else

printf("program terminated normally,"

" but returned a non-zero status\n");

else

printf("program didn't terminate normally\n");


}

else

printf("waitpid() failed\n");

exit(0);

return 0;

OUTPUT:

parent process, pid = 11523


child process, pid = 14188
Program execution successfull
WAIT() :

PROGRAM:

/* C Program to implement Wait() system calls */

#include<stdio.h>

#include<stdlib.h>

#include<sys/wait.h>

#include<unistd.h>
int main()

pid_tcpid;

if (fork()== 0)

exit(0);

else

cpid = wait(NULL);

printf("Parent pid = %d\n", getpid());

printf("Child pid = %d\n", cpid);

return 0;

Parent pid = 12345678

Child pid = 89546848

EXIT():

PROGRAM:

/* C Program to implement Exit() system calls */

#include <stdio.h>

#include <stdlib.h>

int main(void)

{
printf("START");

exit(0);

printf("End of program");

OUTPUT:

START

EX-3

Simulate the following a) Multiprogramming with a fixed number of tasks (MFT) b) Multiprogramming
with a variable number of tasks (MVT)
DESCRIPTION:

MFT : Multiprogramming with a Fixed number of Tasks is one of the old memory management
techniques in which the memory is partitioned into fixed size partitions and each job is assigned to a
partition. The memory assigned to a partition does not change.

MVT : Multiprogramming with a Variable number of Tasks is the memory management technique in
which each job gets just the amount of memory it needs. That is, the partitioning of memory is dynamic
and changes as jobs enter and leave the system. MVT is a more ``efficient'' user of resources. MFT
suffers with the problem of internal fragmentation and MVT suffers with external fragmentation.

PROGRAM

/* C Program to implement Multiprogramming with a fixed number of tasks (MFT)*/

#include<stdio.h>
#include<conio.h>
main()
{
int ms, bs, nob, ef,n, mp[10],tif=0;
int i,p=0;
clrscr();
printf("Enter the total memory available (in Bytes) -- ");
scanf("%d",&ms);
printf("Enter the block size (in Bytes) -- ");
scanf("%d", &bs);
nob=ms/bs;
ef=ms - nob*bs;
printf("\nEnter the number of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter memory required for process %d (in Bytes)-- ",i+1);
scanf("%d",&mp[i]);
}
printf("\nNo. of Blocks available in memory -- %d",nob);
printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION");
for(i=0;i<n && p<nob;i++)
{
printf("\n %d\t\t%d",i+1,mp[i]);
if(mp[i] > bs)
printf("\t\tNO\t\t---");
else
{
printf("\t\tYES\t%d",bs-mp[i]);
tif = tif + bs-mp[i];
p++;
}
}
if(i<n)
printf("\nMemory is Full, Remaining Processes cannot be accomodated");
printf("\n\nTotal Internal Fragmentation is %d",tif);
printf("\nTotal External Fragmentation is %d",ef);
getch();
}

OUTPUT:

Enter the total memory available (in Bytes) -- 1000


Enter the block size (in Bytes)-- 300
Enter the number of processes – 5
Enter memory required for process 1 (in Bytes) -- 275
Enter memory required for process 2 (in Bytes) -- 400
Enter memory required for process 3 (in Bytes) -- 290
Enter memory required for process 4 (in Bytes) -- 293
Enter memory required for process 5 (in Bytes) -- 100
No. of Blocks available in memory -- 3
PROCESS MEMORY-REQUIRED ALLOCATED INTERNAL-FRAGMENTATION
1 275 YES 25
2 400 NO -----
3 290 YES 10
4 293 YES 7
Memory is Full, Remaining Processes cannot be accommodated
Total Internal Fragmentation is 42
Total External Fragmentation is 100

MVT :

PROGRAM:

/* C Program to implement Multiprogramming with a variable number of tasks (MVT)*/

#include<stdio.h>
#include<conio.h>
main()
{
int ms,mp[10],i, temp,n=0;
char ch = 'y';
clrscr();
printf("\nEnter the total memory available (in Bytes)-- ");
scanf("%d",&ms);
temp=ms;
for(i=0;ch=='y';i++,n++)
{
printf("\nEnter memory required for process %d (in Bytes) -- ",i+1);
scanf("%d",&mp[i]);
if(mp[i]<=temp)
{
printf("\nMemory is allocated for Process %d ",i+1);
temp = temp - mp[i];
}
else
{
printf("\nMemory is Full");
break;
}
printf("\nDo you want to continue(y/n) -- ");
scanf(" %c", &ch);
}
printf("\n\nTotal Memory Available -- %d", ms);
printf("\n\n\tPROCESS\t\t MEMORY ALLOCATED ");
for(i=0;i<n;i++)
printf("\n \t%d\t\t%d",i+1,mp[i]);
printf("\n\nTotal Memory Allocated is %d",ms-temp);
printf("\nTotal External Fragmentation is %d",temp);
getch();
}

OUTPUT

Enter the total memory available (in Bytes) -- 1000


Enter memory required for process 1 (in Bytes) -- 400
Memory is allocated for Process 1
Do you want to continue(y/n) -- y
Enter memory required for process 2 (in Bytes) -- 275
Memory is allocated for Process 2
Do you want to continue(y/n) -- y
Enter memory required for process 3 (in Bytes) -- 550
Memory is Full
Total Memory Available -- 1000
PROCESS MEMORY-ALLOCATED
1 400
2 275
Total Memory Allocated is 675

Total External Fragmentation is 325


EX-4
Simulate Bankers Algorithm for Dead Lock Avoidance
DESCRIPTION:
The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for
safety by simulating the allocation for predetermined maximum possible amounts of all
resources, then makes an “s-state” check to test for possible activities, before deciding whether
allocation should be allowed to continue.
Following Data structures are used to implement the Banker’s Algorithm:
Let ‘n’ be the number of processes in the system and ‘m’ be the number of resources types.
Available :
· It is a 1-d array of size ‘m’ indicating the number of available resources of each type.
· Available[ j ] = k means there are ‘k’ instances of resource type Rj
Max :
· It is a 2-d array of size ‘n*m’ that defines the maximum demand of each process in a
system.
· Max[i, j ] = k means process Pi may request at most ‘k’ instances of resource type Rj.
Allocation :
· It is a 2-d array of size ‘n*m’ that defines the number of resources of each type currently
allocated to each process.
· Allocation[i, j ] = k means process Pi is currently allocated ‘k’ instances of resourcetype Rj
Need :
· It is a 2-d array of size ‘n*m’ that indicates the remaining resource need of each process.
· Need [ i, j ] = k means process Pi currently allocated ‘k’ instances of resource type Rj
· Need [ i, j ] = Max [ i, j ] – Allocation [ i, j ]

PROGRAM:

/* C Program to implement Dead Lock Avoidance using Banker’s algorithm */

#include <stdio.h>

#include <stdlib.h>

int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10], safeSequence[10];
int p, r, i, j, process, count;
count = 0;

printf("Enter the no of processes : ");

scanf("%d", &p);

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


completed[i] = 0;

printf("\n\nEnter the no of resources : ");


scanf("%d", &r);

printf("\n\nEnter the Max Matrix for each process : ");


for(i = 0; i< p; i++)
{
printf("\nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}

printf("\n\nEnter the allocation for each process : ");


for(i = 0; i< p; i++)
{
printf("\nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
}

printf("\n\nEnter the Available Resources : ");


for(i = 0; i< r; i++)
scanf("%d", &avail[i]);

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

for(j = 0; j < r; j++)


need[i][j] = Max[i][j] - alloc[i][j];

do
{
printf("\n Max matrix:\tAllocation matrix:\n");

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


{
for( j = 0; j < r; j++)
printf("%d ", Max[i][j]);
printf("\t\t");
for( j = 0; j < r; j++)
printf("%d ", alloc[i][j]);
printf("\n");
}

process = -1;

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


{

if(completed[i] == 0)//if not completed


{

process = i ;
for(j = 0; j < r; j++)
{
if(avail[j] < need[i][j])
{
process = -1;
break;
}
}
}
if(process != -1)
break;
}

if(process != -1)
{
printf("\nProcess %d runs to completion!", process + 1);
safeSequence[count] = process + 1;
count++;
for(j = 0; j < r; j++)
{
avail[j] += alloc[process][j];
alloc[process][j] = 0;
Max[process][j] = 0;
completed[process] = 1;
}
}
}
while(count != p && process != -1);

if(count == p)
{
printf("\nThe system is in a safe state!!\n");
printf("Safe Sequence : < ");
for( i = 0; i< p; i++)
printf("%d ", safeSequence[i]);
printf(">\n");
}

else

printf("\nThe system is in an unsafe state!!");

OUTPUT:

Enter the no of processes : 5

Enter the no of resources : 3

Enter the Max Matrix for each process :

For process 1 : 7

5
3

For process 2 : 3

For process 3 : 7

For process 4 : 2

For process 5 : 4

Enter the allocation for each process :

For process 1 : 0

For process 2 : 2

For process 3 : 3

For process 4 : 2

1
1

For process 5 : 0

Enter the Available Resources : 3

Max matrix: Allocation matrix:

753 010

322 200

702 302

222 211

433 002

Process 2 runs to completion!

Max matrix: Allocation matrix:

753 010

000 000

702 302

222 211

433 002

Process 3 runs to completion!

Max matrix: Allocation matrix:


753 010

000 000

000 000

222 211

433 002

Process 4 runs to completion!

Max matrix: Allocation matrix:

753 010

000 000

000 000

000 000

433 002

Process 1 runs to completion!

Max matrix: Allocation matrix:

000 000

000 000

000 000

000 000

433 002

Process 5 runs to completion!

The system is in a safe state!!

Safe Sequence :< 2 3 4 1 5 >


EX-5

SimulateBankersAlgorithmforDeadLockPrevention.

DESCRIPTION: We can prevent Deadlock by eliminating any of the above four condition.

· Eliminate Mutual Exclusion : It is not possible to dis-satisfy the mutual exclusion because some
resources, such as the tap drive and printer, are inherently non-shareable.

· Eliminate Hold and wait: Allocate all required resources to the process before start of its execution,
this way hold and wait condition is eliminated but it will lead to low device utilization.

· Eliminate No Preemption: Preempt resources from process when resources required by other high
priority process.

· Eliminate Circular Wait: Each resource will be assigned with a numerical number. A process can
request for the resources only in increasing order of numbering.

PROGRAM:

/* C Program to implement Dead Lock Prevention using Banker’s algorithm */

#include<stdio.h>

void main()

int max[10][10],a1[10][10],av[10],i,j,k,m,n,ne[10][10],flag=0;

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

scanf("%d%d",&m,&n);

printf("\n Enter the maximum matrix:\n");

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

for(j=0;j<n;j++)

scanf("%d",&max[i][j]);
}

printf("\n Enter allocated matrix:\n");

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

for(j=0;j<n;j++)

scanf("%d",&a1[i][j]);

printf("\n The need matrix:\n");

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

for(j=0;j<n;j++)

ne[i][j]=max[i][j]-a1[i][j];

printf("\t%d",ne[i][j]);

printf("\n");

printf("\n Enter available matrix:\n");

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

scanf("%d",&av[i]);

printf("\n Maximum matrix\n");

for(i=0;i<m;i++)
{

for(j=0;j<n;j++)

printf("\t%d",max[i][j]);

printf("\n");

printf("\n Allocated matrix:\n");


for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",a1[i][j]);
}
printf("\n");
}
printf("\n Available matrix:\n");
for(i=0;i<n;i++)
{
printf("%d\t",av[i]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(av[i]>=ne[i][j])
flag=1;
else
flag=0;
}
}
if(flag==0)
printf("\n Unsafe state");
else
printf("\n safe state");
}
OUTPUT:
Enter the matrix dimensions:3 3
Enter the maximum matrix:
368
433
344
Enter allocated matrix:
223
203
124
The need matrix:
145
230
220
Enter available matix:
230
Maximum matrix:
368
433
344
Allocated matrix:
223
203
124
Available matrix:
230
safe state

EX-6
Simulate the following page replacement algorithms. a) First In First Out b) Least Recently Used
a) FIFO :

This is the simplest page replacement algorithm. In this algorithm, operating system keeps track
of all pages in the memory in a queue, oldest page is in the front of the queue. When a page needs to be
replaced page in the front of the queue is selected for removal.

PROGRAM:

/* C Program to implement FIFO Page Replacement algorithms */

#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++)
{
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;
}

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

b)LRU:
On a page fault, the frame that was least recently used in replaced.

PROGRAM:

/* C Program to implement LRU Page Replacement algorithms */

#include<stdio.h>
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++)
{
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++)
{
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);
}

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

EX-7
Simulate the following File allocation strategies a) Sequenced b) Indexed
Hege
AIM: Write a C Program to implement Sequential File Allocation method.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the number of memory partition and their sizes.
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches all the entire memory block until a hole which is big enough is
encountered. It allocates that memory block for the requesting process.
Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can be allocated to
requesting process and allocates if.
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and allocates it to the
process.
Step 7: Analyses all the three memory management techniques and display the best algorithm which
utilizes the memory resources effectively and efficiently.
Step 8: Stop the program.
INDEXED FILE ALLOCATION
AIM: Write a C Program to implement Indexed File Allocation method.
Algorithm:
Step 1: Start.
Step 2: Let n be the size of the buffer
Step 3: check if there are any producer
Step 4: if yes check whether the buffer is full
Step 5: If no the producer item is stored in the buffer
Step 6: If the buffer is full the producer has to wait
Step 7: Check there is any cosumer.If yes check whether the buffer is empty
Step 8: If no the consumer consumes them from the buffer
Step 9: If the buffer is empty, the consumer has to wait.
Step 10: Repeat checking for the producer and consumer till required
Step 11: Terminate the process.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy