MANAV RACHNA
UNIVERSITY
OS LAB
SAGAR AGGARWAL
B-TECH CSE -4A
2K18CSUN01080
1. To swap two numbers without using a temporary variable.
2. To calculate the bill amount for an item given the quantity sold, rate, discount and tax.
3. Program to enter any character. If the entered character is in lower case then convert it into uppercase and if it is
lower case then convert it into upper case.
4. To enter a character and determine whether it is vowel or not.
5. Program to display a menu that offers five options: Read three numbers, calculate total, average, display the
smallest and largest value.
7. To find the Fibonacci using recursive function.
8. To insert a number at a given location in an array.
10. Accept any two strings from the user. Display whether both the strings are equal or not.(do not use standard
functions).
11. Write a program to accept a list of 10 integers in an array, pass the starting address of array in sum function,
calculate the sum of the array elements in the function and return the sum calculated in the main function.
12. Program to add two numbers using Command Line Arguments
LAB 2-3
Q1
Q2
Q3
LAB 5-7
Q1
FCFS
OUTPUT
Q2 SJF
OUTPUT
Q3 SRTF
OUTPUT
Q4 ROUND ROBIN
OUTPUT
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
Lab-9
Laboratory Objective: To implement scheduling algorithms in C.
Learning Outcome: Implementation of scheduling algorithms.
1. Implement Priority Scheduling algorithm for three process having the following Burst Time and
Priorities:
Process Burst Time Priority
1 5 2
2 7 1
3 6 3
4 5 4
OUTPUT
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
Lab-10
Laboratory Objective: To implement scheduling algorithms.
Learning Outcome: Implementation of scheduling algorithms.
2. Implement Producer Consumer Problem using Semaphore:
OUTPUT
OS LAB 11
1- FIRST FIT
#include<stdio.h>
void main()
{
int bsize[10],psize[10],bno, pno,flags[10], allocation[10], i, j;
for(i = 0; i < 10; i++)
{
flags[i]= 0;
allocation[i]= -1;
}
printf("Enterno.of blocks: ");
scanf("%d",&bno);
printf("nEntersize ofeach block: ");
for(i = 0; i < bno; i++)
scanf("%d",&bsize[i]);
printf("nEnterno. ofprocesses:");
scanf("%d",&pno);
printf("nEntersize ofeach process: ");
for(i = 0; i < pno; i++)
scanf("%d",&psize[i]);
for(i = 0; i < pno; i++) //allocation as per first fit
for(j= 0; j < bno; j++)
if(flags[j]== 0 && bsize[j]>= psize[i])
{
allocation[j]= i;
flags[j]= 1;
break;
}
//display allocationdetails
printf("nBlockno.tsizettprocessno.ttsize");
for(i = 0; i < bno; i++)
{
printf("n%dtt%dtt",i+1, bsize[i]);
if(flags[i]== 1)
printf("%dttt%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Notallocated");
}
}
OUTPUT
2- BEST FIT
#include<stdio.h>
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
static int barray[20],parray[20];
printf("ntttMemory Management Scheme - Best Fit");
printf("nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
printf("nEnter the size of the blocks:-n");
for(i=1;i<=nb;i++)
{
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
printf("nEnter the size of the processes :-n");
for(i=1;i<=np;i++)
{
printf("Process no.%d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barray[j]!=1)
{
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
parray[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
}
printf("nProcess_notProcess_sizetBlock_notBlock_sizetFragment");
for(i=1;i<=np && parray[i]!=0;i++)
printf("n%dtt%dtt%dtt%dtt%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}
OUTPUT
3- WORST FIT
#include<stdio.h>
int main()
{
int fragments[10], blocks[10], files[10];
int m, n, number_of_blocks, number_of_files, temp, top = 0;
static int block_arr[10], file_arr[10];
printf("nEnter the Total Number of Blocks:t");
scanf("%d",&number_of_blocks);
printf("Enter the Total Number of Files:t");
scanf("%d",&number_of_files);
printf("nEnter the Size of the Blocks:n");
for(m = 0; m < number_of_blocks; m++)
{
printf("Block No.[%d]:t", m + 1);
scanf("%d", &blocks[m]);
}
printf("Enter the Size of the Files:n");
for(m = 0; m < number_of_files; m++)
{
printf("File No.[%d]:t", m + 1);
scanf("%d", &files[m]);
}
for(m = 0; m < number_of_files; m++)
{
for(n = 0; n < number_of_blocks; n++)
{
if(block_arr[n] != 1)
{
temp = blocks[n] - files[m];
if(temp >= 0)
{
if(top < temp)
{
file_arr[m] = n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]] = 1;
top = 0;
}
}
printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment");
for(m = 0; m < number_of_files; m++)
{
printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]],
fragments[m]);
}
printf("n");
return 0;
}
OUTPUT
OS LAB 12
OPTIMAL PAGE REPLACEMENT ALGO
#include<stdio.h>
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k,
pos, max, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter page reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
flag3 =0;
for(j = 0; j < no_of_frames; ++j){
temp[j] = -1;
for(k = i + 1; k < no_of_pages; ++k){
if(frames[j] == pages[k]){
temp[j] = k;
break;
}
}
}
for(j = 0; j < no_of_frames; ++j){
if(temp[j] == -1){
pos = j;
flag3 = 1;
break;
}
}
if(flag3 ==0){
max = temp[0];
pos = 0;
for(j = 1; j < no_of_frames; ++j){
if(temp[j] > max){
max = temp[j];
pos = j;
}
}
}
frames[pos] = pages[i];
faults++;
}
printf("n");
for(j = 0; j < no_of_frames; ++j){
printf("%dt", frames[j]);
}
}
printf("nnTotal Page Faults = %d", faults);
return 0;
}
OUTPUT
LRU PAGE REPLACEMENT ALGORITHM
#include<stdio.h>
int findLRU(int time[], int n){
int i, minimum = time[0], pos = 0;
for(i = 1; i < n; ++i){
if(time[i] < minimum){
minimum = time[i];
pos = i;
}
}
return pos;
}
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j,
pos, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
counter++;
faults++;
frames[j] = pages[i];
time[j] = counter;
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
pos = findLRU(time, no_of_frames);
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
}
printf("n");
for(j = 0; j < no_of_frames; ++j){
printf("%dt", frames[j]);
}
}
printf("nnTotal Page Faults = %d", faults);
return 0;
}
OUTPUT
FIFO PAGE REPLACEMENT ALGO
#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 stringt page framesn");
for(i=1;i<=n;i++)
{
printf("%dtt",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("%dt",frame[k]);
}
printf("n");
}
printf("Page Fault Is %d",count);
return 0;
}
OUTPUT

Operating system labs

  • 1.
    MANAV RACHNA UNIVERSITY OS LAB SAGARAGGARWAL B-TECH CSE -4A 2K18CSUN01080
  • 2.
    1. To swaptwo numbers without using a temporary variable. 2. To calculate the bill amount for an item given the quantity sold, rate, discount and tax.
  • 3.
    3. Program toenter any character. If the entered character is in lower case then convert it into uppercase and if it is lower case then convert it into upper case. 4. To enter a character and determine whether it is vowel or not.
  • 4.
    5. Program todisplay a menu that offers five options: Read three numbers, calculate total, average, display the smallest and largest value.
  • 5.
    7. To findthe Fibonacci using recursive function.
  • 6.
    8. To inserta number at a given location in an array. 10. Accept any two strings from the user. Display whether both the strings are equal or not.(do not use standard functions).
  • 7.
    11. Write aprogram to accept a list of 10 integers in an array, pass the starting address of array in sum function, calculate the sum of the array elements in the function and return the sum calculated in the main function.
  • 8.
    12. Program toadd two numbers using Command Line Arguments LAB 2-3 Q1
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    OUTPUT DEPARTMENT OF COMPUTERSCIENCE & TECHNOLOGY Lab-9 Laboratory Objective: To implement scheduling algorithms in C. Learning Outcome: Implementation of scheduling algorithms.
  • 15.
    1. Implement PriorityScheduling algorithm for three process having the following Burst Time and Priorities: Process Burst Time Priority 1 5 2 2 7 1 3 6 3 4 5 4
  • 16.
  • 17.
    DEPARTMENT OF COMPUTERSCIENCE & TECHNOLOGY Lab-10 Laboratory Objective: To implement scheduling algorithms. Learning Outcome: Implementation of scheduling algorithms. 2. Implement Producer Consumer Problem using Semaphore:
  • 19.
  • 22.
    OS LAB 11 1-FIRST FIT #include<stdio.h> void main() { int bsize[10],psize[10],bno, pno,flags[10], allocation[10], i, j; for(i = 0; i < 10; i++) { flags[i]= 0; allocation[i]= -1; } printf("Enterno.of blocks: "); scanf("%d",&bno); printf("nEntersize ofeach block: "); for(i = 0; i < bno; i++) scanf("%d",&bsize[i]);
  • 23.
    printf("nEnterno. ofprocesses:"); scanf("%d",&pno); printf("nEntersize ofeachprocess: "); for(i = 0; i < pno; i++) scanf("%d",&psize[i]); for(i = 0; i < pno; i++) //allocation as per first fit for(j= 0; j < bno; j++) if(flags[j]== 0 && bsize[j]>= psize[i]) { allocation[j]= i; flags[j]= 1; break; } //display allocationdetails printf("nBlockno.tsizettprocessno.ttsize"); for(i = 0; i < bno; i++) { printf("n%dtt%dtt",i+1, bsize[i]); if(flags[i]== 1) printf("%dttt%d",allocation[i]+1,psize[allocation[i]]); else printf("Notallocated"); } }
  • 24.
  • 25.
    2- BEST FIT #include<stdio.h> voidmain() { int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999; static int barray[20],parray[20]; printf("ntttMemory Management Scheme - Best Fit"); printf("nEnter the number of blocks:"); scanf("%d",&nb); printf("Enter the number of processes:"); scanf("%d",&np); printf("nEnter the size of the blocks:-n"); for(i=1;i<=nb;i++) { printf("Block no.%d:",i); scanf("%d",&b[i]); } printf("nEnter the size of the processes :-n"); for(i=1;i<=np;i++) { printf("Process no.%d:",i); scanf("%d",&p[i]); } for(i=1;i<=np;i++) { for(j=1;j<=nb;j++) { if(barray[j]!=1) { temp=b[j]-p[i]; if(temp>=0) if(lowest>temp) { parray[i]=j; lowest=temp;
  • 26.
  • 27.
    3- WORST FIT #include<stdio.h> intmain() { int fragments[10], blocks[10], files[10]; int m, n, number_of_blocks, number_of_files, temp, top = 0; static int block_arr[10], file_arr[10]; printf("nEnter the Total Number of Blocks:t"); scanf("%d",&number_of_blocks); printf("Enter the Total Number of Files:t"); scanf("%d",&number_of_files); printf("nEnter the Size of the Blocks:n"); for(m = 0; m < number_of_blocks; m++) { printf("Block No.[%d]:t", m + 1); scanf("%d", &blocks[m]); } printf("Enter the Size of the Files:n"); for(m = 0; m < number_of_files; m++) { printf("File No.[%d]:t", m + 1); scanf("%d", &files[m]); } for(m = 0; m < number_of_files; m++) { for(n = 0; n < number_of_blocks; n++) { if(block_arr[n] != 1) { temp = blocks[n] - files[m]; if(temp >= 0) { if(top < temp) { file_arr[m] = n; top = temp; } }
  • 28.
    } fragments[m] = top; block_arr[file_arr[m]]= 1; top = 0; } } printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment"); for(m = 0; m < number_of_files; m++) { printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]); } printf("n"); return 0; } OUTPUT
  • 29.
    OS LAB 12 OPTIMALPAGE REPLACEMENT ALGO #include<stdio.h> int main() { int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos, max, faults = 0; printf("Enter number of frames: "); scanf("%d", &no_of_frames); printf("Enter number of pages: "); scanf("%d", &no_of_pages); printf("Enter page reference string: "); for(i = 0; i < no_of_pages; ++i){ scanf("%d", &pages[i]); } for(i = 0; i < no_of_frames; ++i){ frames[i] = -1; } for(i = 0; i < no_of_pages; ++i){ flag1 = flag2 = 0; for(j = 0; j < no_of_frames; ++j){ if(frames[j] == pages[i]){ flag1 = flag2 = 1; break; } } if(flag1 == 0){ for(j = 0; j < no_of_frames; ++j){ if(frames[j] == -1){ faults++; frames[j] = pages[i]; flag2 = 1; break; } } }
  • 30.
    if(flag2 == 0){ flag3=0; for(j = 0; j < no_of_frames; ++j){ temp[j] = -1; for(k = i + 1; k < no_of_pages; ++k){ if(frames[j] == pages[k]){ temp[j] = k; break; } } } for(j = 0; j < no_of_frames; ++j){ if(temp[j] == -1){ pos = j; flag3 = 1; break; } } if(flag3 ==0){ max = temp[0]; pos = 0; for(j = 1; j < no_of_frames; ++j){ if(temp[j] > max){ max = temp[j]; pos = j; } } } frames[pos] = pages[i]; faults++; } printf("n"); for(j = 0; j < no_of_frames; ++j){ printf("%dt", frames[j]); } } printf("nnTotal Page Faults = %d", faults); return 0;
  • 31.
    } OUTPUT LRU PAGE REPLACEMENTALGORITHM #include<stdio.h>
  • 32.
    int findLRU(int time[],int n){ int i, minimum = time[0], pos = 0; for(i = 1; i < n; ++i){ if(time[i] < minimum){ minimum = time[i]; pos = i; } } return pos; } int main() { int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos, faults = 0; printf("Enter number of frames: "); scanf("%d", &no_of_frames); printf("Enter number of pages: "); scanf("%d", &no_of_pages); printf("Enter reference string: "); for(i = 0; i < no_of_pages; ++i){ scanf("%d", &pages[i]); } for(i = 0; i < no_of_frames; ++i){ frames[i] = -1; } for(i = 0; i < no_of_pages; ++i){ flag1 = flag2 = 0; for(j = 0; j < no_of_frames; ++j){ if(frames[j] == pages[i]){ counter++; time[j] = counter; flag1 = flag2 = 1; break; } } if(flag1 == 0){ for(j = 0; j < no_of_frames; ++j){ if(frames[j] == -1){ counter++; faults++; frames[j] = pages[i];
  • 33.
    time[j] = counter; flag2= 1; break; } } } if(flag2 == 0){ pos = findLRU(time, no_of_frames); counter++; faults++; frames[pos] = pages[i]; time[pos] = counter; } printf("n"); for(j = 0; j < no_of_frames; ++j){ printf("%dt", frames[j]); } } printf("nnTotal Page Faults = %d", faults); return 0; } OUTPUT
  • 34.
    FIFO PAGE REPLACEMENTALGO #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 stringt page framesn"); for(i=1;i<=n;i++) { printf("%dtt",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++;
  • 35.