Posts

Showing posts from July, 2017

Scheduling methods

Scheduling algorithms may use different criteria for selecting process from the ready list. In general,scheduling algorithm may be preemptive or nonpreemptive. Four circumstances are used for making scheduling decisions. 1. When a process switches from running state to the waiting state. 2. When a process switches from the running state to the ready state. 3. When a process switches from the waiting state to the ready state. 4. When a process terminates. Preemptive scheduling takes place for circumstances 2 and 3. Nonpreemptive scheduling takes place under circumstances 1 and 4. For 1 and 4 circumstances, scheduling is not possible and for remaining circumstance, scheduling is possible. In preemptive scheduling, a running process may be replaced by a higher priority process at any time. Preemptive scheduling is more responsive but it imposes higher overhead since each process rescheduling entails a complete process switch. In Nonpreemptive scheduling, once the CPU has been all...

MFT (Multi programming with Fixed no of Tasks)

#include<stdio.h> #include<conio.h> void main() { int m,p,s,p1; int m1[4],i,f,f1=0,f2=0,fra1,fra2,s1; clrscr(); printf("Enter the memory size:"); scanf("%d",&m); printf("Enter the no of partitions:"); scanf("%d",&p); s=m/p; printf("Each partn size is:%d",s); printf("\nEnter the no of processes:"); scanf("%d",&p1); for(i=0;i<p1;i++) { printf("\nEnter the memory req for process%d:",i+1); scanf("%d",&m1[i]); if(m1[i]<=s) { printf("\nProcess is allocated in partition%d",i+1); fra1=s-m1[i]; printf("\nInternal fragmentation for process is:%d",fra1); f1=f1+fra1; } else { printf("\nProcess not allocated in partition%d",i+1); s1=m1[i]-s; fra2=s-s1; f2=f2+fra2; printf("\nExternal fragmentation for partition is:%d",fra2); } } printf("\nProcess\tmemory\tallocatedmemory"); for(i=0;i<p1;i++) pr...

MVT(Multi[programming with Variable no of Tasks)

#include<stdio.h>  #include<conio.h>  void main()  {  int m=0,m1=0,m2=0,p,count=0,i;  clrscr();  printf("Enter the memory capacity:"); scanf("%d",&m); printf("Enter the no of processes:");  scanf("%d",&p); for(i=0;i<p;i++)  {  printf("\nEnter memory req for process%d: ",i+1);  scanf("%d",&m1); count=count+m1;  if(m1<=m)  {  if(count==m)  {  printf("There is no further memory remaining:");  }  else  {  printf("The memory allocated for process%d is: %d ",i+1,m);  m2=m-m1;  printf("\nRemaining memory is: %d",m2);  m=m2; }  }  else  {  printf("Memory is not allocated for process%d",i+1);  }  printf("\nExternal fragmentation for this process is:%d",m2);  }  getch();  }

ROUND ROBIN with Arrival Time

#include<stdio.h> #include<conio.h> void main() { int et[30],ts,n,i,x=0,tot=0; char pn[10][10]; clrscr(); printf("Enter the no of processes:"); scanf("%d",&n); printf("Enter the time quantum:"); scanf("%d",&ts); for(i=0;i<n;i++) { printf("enter process name & estimated time:"); scanf("%s %d",pn[i],&et[i]); } printf("The processes are:"); for(i=0;i<n;i++) printf("process %d: %s\n",i+1,pn[i]); for(i=0;i<n;i++) tot=tot+et[i]; while(x!=tot) { for(i=0;i<n;i++) { if(et[i]>ts) { x=x+ts; printf("\n %s -> %d",pn[i],ts); et[i]=et[i]-ts; } else if((et[i]<=ts)&&et[i]!=0) { x=x+et[i]; printf("\n %s -> %d",pn[i],et[i]); et[i]=0;} } } printf("\n Total Estimated Time:%d",x); getch(); } 

PRIORITY with Arrival Time

#include<stdio.h>  #include<conio.h>  #include<string.h>  void main()  {  int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];  int totwt=0,totta=0;  float awt,ata; char pn[10][10],t[10];  clrscr();  printf("Enter the number of process:");  scanf("%d",&n); for(i=0;i<n;i++)  {  printf("Enter process name,arrivaltime,execution time & priority:"); flushall();  scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]); }  for(i=0;i<n;i++)  for(j=0;j<n;j++)  {  if(p[i]<p[j]) {  temp=p[i]; p[i]=p[j]; p[j]=temp;  temp=at[i];  at[i]=at[j]; at[j]=temp; temp=et[i];  et[i]=et[j]; et[j]=temp; strcpy(t,pn[i]);  strcpy(pn[i],pn[j]);  strcpy(pn[j],t);  }  }  for(i=0;i<n;i++)  { if(i==0) { st[i]=at[i]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; } else { st[i]=ft[i-1]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et...

SJF with Arrival Time

#include<stdio.h> #include<conio.h> #include<string.h> void main() { int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10]; int totwt=0,totta=0; float awt,ata; char pn[10][10],t[10]; clrscr(); printf("Enter the number of process:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter process name, arrival time & execution time:"); flushall(); scanf("%s%d%d",pn[i],&at[i],&et[i]); } for(i=0;i<n;i++) for(j=0;j<n;j++) { if(et[i]<et[j]) { temp=at[i]; at[i]=at[j]; at[j]=temp; temp=et[i]; et[i]=et[j]; et[j]=temp; strcpy(t,pn[i]); strcpy(pn[i],pn[j]); strcpy(pn[j],t); } } for(i=0;i<n;i++) { if(i==0) st[i]=at[i]; else st[i]=ft[i-1]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; totwt+=wt[i]; totta+=ta[i]; } awt=(float)totwt/n; ata=(float)totta/n; printf("\nPname\tarrivaltime\texecutiontime\twaitingtime\ttatime"); for(i=0;i<n;i++) printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d",pn...

FCFS with Arrival Time

#include<stdio.h>  #include<conio.h>  void main()  {  `char pn[10][10];  int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,n;  int totwt=0,tottat=0;  clrscr();  printf("Enter the number of processes:");  scanf("%d",&n); for(i=0;i<n;i++)  {  printf("Enter the Process Name, Arrival Time & Burst Time:");  scanf("%s%d%d",&pn[i],&arr[i],&bur[i]);  }  for(i=0;i<n;i++)  {  if(i==0)  {  star[i]=arr[i]; wt[i]=star[i]-arr[i]; finish[i]=star[i]+bur[i]; tat[i]=finish[i]-arr[i];  }  else  {  star[i]=finish[i-1]; wt[i]=star[i]-arr[i]; finish[i]=star[i]+bur[i]; tat[i]=finish[i]-arr[i];  }  }  printf("\nPName Arrtime Burtime Start TAT Finish");&#0; for(i=0;i<n;i++)  {  printf("\n%s\t%6d\t\t%6d\t%6d\t%6d\t%6d",pn[i],arr[i],bur[i],star[i],tat[i],finish[i]);  totwt+=wt[i];  tottat+=tat[i];  }  printf(...

OPERATING SYSTEM SERVICES

An operating system provides an environment for the execution of programs. The specific services provided are differing from one operating system to another, but we can identify common classes. These operating system services are provided for the convenience of the programmer to make the programming task easy. Program creation: the operating system provides editors, debuggers, to assist the programmer in creating programs. Programs execution: A number of tasks required to execute a program, the tasks include instructions and data must be loaded into main memory, I/O devices and files must be initialized, and other resources must be prepared. The OS handles these tasks for the user. Input/Output operations: A running program may require input and output. This I/O may involve a file or an I/O device. A user program cannot execute I/O operations directly, the OS must provide some means to do so. Error detection: the operating system detects the different types of er...

operating system services

Image
An operating system provides an environment for the execution of programs. The specific services provided are differing from one operating system to another, but we can identify common classes. These operating system services are provided for the convenience of the programmer to make the programming task easy. Program creation: the operating system provides editors, debuggers, to assist the programmer in creating programs. Programs execution: A number of tasks required to execute a program, the tasks include instructions and data must be loaded into main memory, I/O devices and files must be initialized, and other resources must be prepared. The OS handles these tasks for the user. Input/Output operations: A running program may require input and output. This I/O may involve a file or an I/O device. A user program cannot execute I/O operations directly, the OS must provide some means to do so. Error detection: the operating system detects the different types of erro...