Posts

Showing posts from July, 2023

OS LAB ALL MANUAL

 https://1drv.ms/f/s!AmaPagrPD6YSnAKcRJV_hKSBaPUe?e=FK13zq https://1drv.ms/f/s!AmaPagrPD6YSnAKcRJV_hKSBaPUe?e=FK13zq CLICK HERE  

CLOOK DISK SCHEDULING

 #include <stdio.h> #include <stdlib.h> int main() {     int queue[20], n, head, i, j, seek_time = 0, diff, max, min, temp, range;     float avg_seek_time;     printf("Enter the number of requests: ");     scanf("%d", &n);     printf("Enter the queue of disk requests: ");     for(i = 0; i < n; i++)         scanf("%d", &queue[i]);     printf("Enter the initial head position: ");     scanf("%d", &head);     queue[n] = head;     n++;     for(i = 0; i < n; i++)     {         for(j = i; j < n; j++)         {             if(queue[i] > queue[j])             {                 temp = queue[i];                 queue[i] = queue[j];   ...

LOOK Disk Scheduling

#include <stdio.h> #include <stdlib.h> int main() {     int n, i, j, head, seek_time = 0, prev, curr;     printf("Enter the number of requests: ");     scanf("%d", &n);     int requests[n];     printf("Enter the requests: ");     for(i = 0; i < n; i++) {         scanf("%d", &requests[i]);     }     printf("Enter the initial head position: ");     scanf("%d", &head);     prev = head;     for(i = 0; i < n; i++) {         int closest = 999999;         for(j = 0; j < n; j++) {             if(abs(requests[j] - prev) < closest) {                 closest = abs(requests[j] - prev);                 curr = requests[j];             }       ...

Simulate the following CPU scheduling algorithms FCFS

  #include<stdio.h> #include<conio.h> void main() { int n,i,bt[10],wt[10],tt[10],totalwt=0,totaltt=tt[0]; float avgwt,avgtt; clrscr(); printf("\nEnter No.of Processers:"); scanf("%d",&n); printf("\nEnter Elements into Burst Time:"); for (i=0;i<n;i++){ scanf("%d",&bt[i]); } wt[0]=0; tt[0]=bt[0]; for(i=1;i<n;i++) {      // wt[0]=0;        // tt[0]=bt[0]; wt[i]=wt[i-1]+bt[i-1]; tt[i]=wt[i]+bt[i]; totaltt+=tt[i]; totalwt+=wt[i]; } printf("BT\t\tWT\t\tTT\n"); for(i=0;i<n;i++){ printf("%d\t\t%d\t\t%d\n",bt[i],wt[i],tt[i]); } avgtt=totaltt/n; avgwt=totalwt/n; printf("\nAverage Waiting Time is %f\n",avgwt); printf("\nAverage Turnaround Time is %f\n",avgtt); getch(); }

Simulate the following CPU scheduling algorithms SJF

  #include<stdio.h> void main(){   int p[10],bt[10],wt[10],tt[10],n,i,tot_wt=0,tot_tt=bt[0],j,t,c;  float avg_wt,avg_tt;   clrscr();   printf("\nEnter no of Processes");   scanf("%d",&n);   printf("Enter process name  and  of process Alternatively");   for(i=0;i<n;i++)   {     scanf("%d%d",&p[i],&bt[i]);   }   printf("SJF order of the Process is:\t");   for(i=0;i<n;i++)    {     for(j=i+1;j<n;j++)     {      if(bt[j]<bt[i])      {       t=bt[i];       c=p[i];       bt[i]=bt[j];       p[i]=p[j];       bt[j]=t;       p[j]=c;      }     } printf("p%d\t",p[i]); }    tot_tt=bt[0];     wt[0]=0;   tt[0]=bt[0];   for(i=1;i<n;i++)   {    wt[i]=wt[i-1]+bt[i-1];   ...

Simulate the following CPU scheduling algorithms Priority

 #include<stdio.h>  #include<conio.h>  #include<math.h>  void main()  {   int n,bt[10],wt[10],pt[10],tt[10],swt=0,stt=0,t,t1,i,j; float awt,att; clrscr(); printf("Enter number of process : "); scanf("%d",&n); printf("Enter %d process times : ",n); for(i=0;i<n;i++) scanf("%d",&bt[i]); printf("Enter %d process priorites : ",n); for(i=0;i<n;i++) scanf("%d",&pt[i]); printf("Cpu time and priorities before sorting\n"); for(i=0;i<n;i++) printf("%d\t%d\n",bt[i],pt[i]); printf("Cpu times and priorities after sorting\n"); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(pt[i]>pt[j]) { t=pt[i]; pt[i]=pt[j]; pt[j]=t; t1=bt[i]; bt[i]=bt[j]; bt[j]=t1; } }        }        for(i=0;i<n;i++) printf("%d\t%d\n",bt[i],pt[i]); wt[0]=0; tt[0]=stt=bt[0]; for(i=1;i<n;i++) ...

Simulate the following CPU scheduling algorithms Round Robin

  #include<stdio.h> #include<conio.h> #include<math.h> void main() {  char pname[20][10];  int n,i,bt[20],ptime[20],tq,count=0,tot=0,wt[20],twt=0,ttt=0,e[20];  float awt,att;  clrscr();  printf("enter number of process : ");  scanf("%d",&n);  for(i=1;i<=n;i++)  {  printf("enter %d process name : ",i);  scanf(" %s",pname[i]);  printf("enter %d process time : ",i);  scanf("%d",&ptime[i]);  bt[i]=ptime[i];  }  printf("enter time quantum : ");  scanf("%d",&tq);  while(count<n)  { for(i=1;i<=n;i++) { if(bt[i]!=0) { if(bt[i]<=tq) { tot+=bt[i]; bt[i]=0; e[i]=tot; count++; } else { bt[i]=bt[i]-tq; tot+=tq; } printf("%s\t%d\n",pname[i],bt[i]); } }  } for(i=1;i<=n;i++) { wt[i]=e[i]-ptime[i]; twt+=wt[i]; ttt+=e...

Simulate the following CPU scheduling algorithms FCFS With Arrival Time

  #include<stdio.h> #include<conio.h> void main() { int n,bt[5],wt[5],tt[5],t,c,d,j,i,at[5],p[5]; int twt=0,totaltt=0; float avgtt=0,avgwt=0; wt[0]=0; clrscr(); printf("Enter No of Processors:"); scanf("%d",&n); printf("\nEnter Process Name,Burst Time and Arrival Time:\n"); for(i=0;i<n;i++) {   scanf("%d%d%d",&p[i],&bt[i],&at[i]); } tt[0]=bt[0]; wt[0]=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(at[i]>at[j]) { t=at[i]; at[i]=at[j]; at[j]=t; c=p[i]; p[i]=p[j]; p[j]=c; d=bt[i]; bt[i]=bt[j]; bt[j]=d; } } } for(i=1;i<n;i++) { wt[i]=wt[i-1]+bt[i-1]-at[i]; tt[i]=wt[i]+bt[i]; } for(i=0;i<n;i++) { twt+=wt[i]; totaltt+=tt[i]; } printf("Pname\tBT\t AT\tWT\tTT\t\n"); for(i=0;i<n;i++) { printf("P%d\t%d\t%d\t%d\t%d\n",p[i],bt[i],at[i],wt[i],tt[i]); } avgw...

Simulate MFT

  #include<stdio.h> #include<conio.h> #include<math.h> void main() { int mm,osm,size[1000],i,n,rem,internal=0,part; clrscr(); printf("Enter Total Memory Size:"); scanf("%d",&mm); printf("\nEnter OS Size:"); scanf("%d",&osm); rem=mm-osm; printf("\nRemaming memory for use is:%d",rem); printf("\nEnter Number of processes: "); scanf("%d",&n); part=rem/n; for(i=0;i<n;i++) { printf("Enter size of process %d : ", i + 1); scanf("%d", &size[i]); if (size[i] <= part) { printf("\nProcess %d is allotted\n",i + 1); mm=mm-size[i]; internal+=part-size[i]; } else printf("\nProcess %d is blocked\n", i + 1); } printf("Total internal fragmentation : %d\n", internal); getch(); }

Simulate MVT

  #include<stdio.h> #include<conio.h> #include<math.h> void main() { int mm,osm,size[1000],i,n,rem,part; clrscr(); printf("Enter Total Memory Size:"); scanf("%d",&mm); printf("\nEnter OS Size:"); scanf("%d",&osm); mm=mm-osm; printf("\nRemaming memory for use is:%d",mm); while(1) { printf("\nEnter size of process  : "); scanf("%d", &size[i]); if (size[i] <= mm) { printf("\nProcess is allotted\n"); mm=mm-size[i]; } else if(mm<=0){ break; } else printf("\nProcess is blocked\n"); } printf("Total External fragmentation : %d\n", mm); getch(); }

Simulate the following page replacement algorithms FIFO

  #include<stdio.h> #include<conio.h> void main()  { int n,nf,i,j,ref[20],fr[20],count=0,k,hit,flag=0,pgf=0; printf("Enter Number of pages : "); scanf("%d",&n); printf("Enter Page Numbers : "); for(i=0;i<n;i++) { scanf("%d",&ref[i]); } printf("Enter the Number of frames : "); scanf("%d",&nf); printf("Ref. string\tPage frames\n"); for(i=0;i<n;i++) { fr[i]=-1; } for(i=0;i<n;i++) { flag=0; printf("%d\t\t",ref[i]); for(j=0;j<nf;j++) { if(fr[j]==ref[i]) { flag=1;  hit++; break; } } if(flag==0) { if(count>nf-1) { count=0; fr[count]=ref[i]; count+=1; pgf+=1; } else { fr[count]=ref[i]; count+=1; pgf+=1; } for(k=0;k<nf;k++) { printf("%d\t",fr[k]); } } printf("\n"); } printf("Total p...

Simulate the following page replacement algorithms LRU

#include<stdio.h> #include<conio.h> #include<string.h>  int findmin();  int i,j,pf=0,f,n,min,ref[40],frame[10],avail,ind=0,count=0,k,time[10];   void main() {   printf("enter the number of pages : ");   scanf("%d",&n);   printf("enter the page numbers : ");   for(i=0;i<n;i++)   scanf("%d",&ref[i]);   printf("enter the number of frames : ");   scanf("%d",&f);   printf("Page frames:");   printf("\n"); for(i=0;i<f;i++) { frame[i]=-1; time[i]=0; } for(i=0;i<n;i++) { avail=0; for(j=0;j<f;j++) { if(frame[j]==ref[i]) { avail=1; count++; time[j]=count; break; } } if(avail==0) { k=findmin(); frame[k]=ref[i]; count++; time[k]=count; pf++; for(j=0;j<f;j++) { if(frame[j]!=-1) printf("\t%d",frame[j]); } printf("\n"); } } printf("total...

Simulate the following page replacement algorithms Optimal

#include<stdio.h> #include<math.h> int findoptimal(); int i,j,pf=0,nf,r,ffree=0,found,np,max,u,v,ref[40],frame[10],avail,ind[10],k;   void main() { printf("enter the number of pages : "); scanf("%d",&np); printf("enter the page numbers : "); for(i=0;i<np;i++) scanf("%d",&ref[i]); printf("enter the number of frames : "); scanf("%d",&nf); printf("ref. string\tpage frames"); for(i=0;i<nf;i++) {      frame[i]=-1; } for(i=0;i<np;i++) {        printf("\n");        printf("%d\t\t",ref[i]);        avail=0;        for(j=0;j<nf;j++) { if(frame[j]==ref[i]) { avail=1; for(j=0;j<nf;j++) printf("%d\t",frame[j]); break; } } if(avail==0) { if(ffree<nf) { k=ffree; ffree++; } else k=findoptimal(i+1); frame[k]=ref[i]; pf++; for(j=0;j<nf;j++) ...

Simulate Bankers Algorithm for Dead Lock Avoidance

 #include<stdio.h>  #include<conio.h>  #include<math.h>  void main()  {  int seq[10],m,n,i,j,alloc[10][10],max[10][10],need[10][10]={0},avai[10];  int finish[10],flag, npleft,c,k=0;   printf("enter types of resources : ");   scanf("%d",&m);   printf("enter available resources instance of %d types resources\n", m);   for(i=0;i<m;i++)   scanf("%d",&avai[i]);   printf("enter number of processes : ");   scanf("%d",&n);   printf("enter allocation matrix");   for(i=0;i<n;i++)   {   for(j=0;j<m;j++)   {   scanf("%d",&alloc[i][j]);     }   }   printf("enter maximum resource matrix\n");   for(i=0;i<n;i++)   {   for(j=0;j<m;j++)   scanf("%d",&max[i][j]);   }   printf("the given allocation ...

Simulate the following disk scheduling algorithms FCFS

  #include<stdio.h>  #include<conio.h>  void main()  {   int n,i,queue[30],head,diff,seek=0;   printf("enter number of queue elements : ");   scanf("%d",&n);   printf("enter the work queue : ");   for(i=0;i<n;i++)   scanf("%d",&queue[i]);   printf("enter the disk head starting position : ");   scanf("%d",&head);   for(i=0;i<n;i++)   {   diff=abs(head-queue[i]);   seek=seek+diff;   head=queue[i];   }   printf("total seek time : %d\n",seek);  } 

Simulate the following disk scheduling algorithms SSTF

 #include<stdio.h>  #include<conio.h>  void main()  {   int n,i,queue[30],visit[30],head,j,min,seek=0,pos;   printf("enter number of queue elements : ");   scanf("%d",&n);   printf("enter the work queue : ");   for(i=0;i<n;i++)   {   scanf("%d",&queue[i]);   visit[i]=0;   }   printf("enter the disk head starting position : ");   scanf("%d",&head);   for(i=0;i<n;i++)   {   min=999;   for(j=0;j<n;j++)   {   if(visit[j]==0)   {   if(min>abs(head-queue[j]))   {   min=abs(head-queue[j]);   pos=j;   }   }   }   visit[pos]=1;     head=queue[pos];   seek=seek+min;   }   printf("total seek time : %d\n",seek);    }  x

Simulate the following disk scheduling algorithms SCAN

  #include<stdio.h>  #include<conio.h>  void main()  {   int size,n,q[20],visit[20],t,head,pos,seek=0,i,j;   printf("enter number of queue elements : ");   scanf("%d",&n);   printf("enter the work queue : ");   for(i=0;i<n;i++)   {   scanf("%d",&q[i]);   visit[i]=0;   }   printf("enter the disk head starting position : ");   scanf("%d",&head);   for(i=0;i<n;i++)   {   for(j=i+1;j<n;j++)   {   if(q[i]>q[j])   {   t=q[i];   q[i]=q[j];   q[j]=t;   }   }   }   for(i=n;i>=1;i--)   {   if(q[i]<head)   {   seek=seek+abs(head-q[i]);   visit[i]=1;   head=q[i];   }   }   for(i=0;i<n;i++)   {  ...

Simulate the following disk scheduling algorithms CSCAN

  #include<stdio.h>  #include<conio.h>  void main()  {   int size,n,q[20],visit[20],t,head,pos,seek=0,i,j,max,tot=0;   float average=0;   printf("enter the max range of disk : ");   scanf("%d",&size);   max=size-1;   printf("enter the disk head starting position : ");   scanf("%d",&head);   printf("enter number of queue elements : ");   scanf("%d",&n);   printf("enter the work queue : ");   for(i=0;i<n;i++)   {   scanf("%d",&q[i]);   visit[i]=0;   }   for(i=0;i<n;i++)   {   for(j=i+1;j<n;j++)   {   if(q[i]>q[j])   {   t=q[i];   q[i]=q[j];   q[j]=t;   }   }   }   for(i=0;i<n;i++)   {   if(q[i]>head)   {   see...

Practice session on UNIX commands and vi editor

Aim:  To practice UNIX commands and vi editor Description:              Linux is an open source operating system like other OS such as Ms windows, Apple, Mac OS, Google, Android.              Unix is also an OS like Linux. But it is a commercial OS. It consists of three parts, 1.Kernal 2.Shell 3.Programs Linux Shell or Terminal:              A shell is a program that receives commands from the user and gives it to the OS to process and it shows the output. ü    The commands are executed in the Linux terminal. ü    The terminal is a command Line interface to interact with the system which is similar to the command prompt in the windows OS. ü    Commands in Linux are case sensitive. Telnet 192.168.7.2 Login:    cse21-d5 Password: cse21-d5              [cse21-d5 @localhost ~]$ Pwd command:     ...