What is disk scheduling:-
Disk scheduling is schedule I/O requests arriving for the disk. It is important because:-
- Multiple I/O requests may arrive by different processes and only one I/O request can be served at a time by the disk controller. Thus other I/O requests need to wait in the waiting queue and need to be scheduled.
- Two or more request may be far from each other so can result in greater disk head movement.
- Hard drives are one of the slowest parts of the computer system and thus need to be accessed in an efficient manner.
- Seek Time: Seek time is the time taken to locate the disk head to a specified track where the data is to be read or write. So the disk scheduling algorithm that gives minimum average seek time is better.
- Rotational Latency: Rotational Latency is the time taken by the desired sector of disk to rotate into a position so that it can access the read/write heads. So the disk scheduling algorithm that gives minimum rotational latency is better.
- Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating speed of the disk and number of bytes to be transferred.
- Disk Access Time: Disk Access Time is=( Seek+ Rotational+ transfer time)
There are some Disk scheduling algorithms:-
You can simply click on the link and can find the program of the scheduling algorithms.
codechef problems:-
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
See more:-
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
6 Comments
linked list program
ReplyDelete#include
#include
#include
#define MAX 200
typedef struct dir
{
char fname[20];
int start;
struct dir *next;
}NODE;
NODE *first,*last;
int n,fb,bit[MAX];
void init()
{
int i;
printf("Enter total no.of disk blocks:");
scanf("%d",&n);
fb = n;
for(i=0;i<10;i++)
{
int k = rand()%n;
if(bit[k]!=-2)
{
bit[k]=-2;
fb--;
}
}
}
void show_bitvector()
{
int i;
for(i=0;ifname);
i = p->start;
while(i!=-1)
{
printf("%d->",i);
i=bit[i];
}
printf("NULL\n");
p=p->next;
}
}
void create()
{
NODE *p;
char fname[20];
int i,j,nob;
printf("Enter file name:");
scanf("%s",fname);
printf("Enter no.of blocks:");
scanf("%d",&nob);
if(nob>fb)
{
printf("Failed to create file %s\n",fname);
return;
}
for(i=0;ifname,fname);
p->start=i;
p->next=NULL;
if(first==NULL)
first=p;
else
last->next=p;
last=p;
fb-=nob;
j=i+1;
nob--;
while(nob>0)
{
if(bit[j]==0)
{
bit[i]=j;
i=j;
nob--;
}
j++;
}
bit[i]=-1;
printf("File %s created successully.\n",fname);
}
void delete()
{
char fname[20];
NODE *p,*q;
int nob=0,i,j;
printf("Enter file name to be deleted:");
scanf("%s",fname);
p = q = first;
while(p!=NULL)
{
if(strcmp(p->fname,fname)==0)
break;
q=p;
p=p->next;
}
if(p==NULL)
{
printf("File %s not found.\n",fname);
return;
}
i = p->start;
while(i!=-1)
{
nob++;
j = i;
i = bit[i];
bit[j] = 0;
}
fb+=nob;
if(p==first)
first=first->next;
else if(p==last)
{
last=q;
last->next=NULL;
}
else
q->next = p->next;
free(p);
printf("File %s deleted successfully.\n",fname);
}
int main()
{
int ch;
init();
while(1)
{
printf("1.Show bit vector\n");
printf("2.Create new file\n");
printf("3.Show directory\n");
printf("4.Delete file\n");
printf("5.Exit\n");
printf("Enter your choice (1-5):");
scanf("%d",&ch);
switch(ch)
{
case 1:
show_bitvector();
break;
case 2:
create();
break;
case 3:
show_dir();
break;
case 4:
delete();
break;
case 5:
exit(0);
}
}
return 0;
}
ReplyDeletebro plz dont delete this
os indexed file
#include
main()
{
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Enter starting block and size of file%d:",i+1);
scanf("%d%d",&sb[i],&s[i]);
printf("Enter blocks occupied by file%d:",i+1);
scanf("%d",&m[i]);
printf("enter blocks of file%d:",i+1);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
} printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
}printf("\nEnter file name:");
scanf("%d",&x);
printf("file name is:%d\n",x);
i=x-1;
printf("Index is:%d",sb[i]);
printf("Block occupied are:");
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
}
ReplyDeletebanker program
#include
#include
void print(int x[][10],int n,int m)
{
int i,j;
for(i=0;i N[pid][i]){
printf("\n Error encountered.\n");
exit(0);
}
for(i=0;i AV[0][i]){
printf("\n Resources unavailable.\n");
exit(0);
}
for(i=0;i W[0][j])
flag=1;
}
if(flag == 0 && F[i] == 0){
for(j=0;j<m;j++)
W[0][j]+=A[i][j];
F[i]=1;
pflag++;
a[x++]=i;
}
}
}
if(pflag == n)
return 1;
}
return 0;
}
//Banker's Algorithm
void accept(int A[][10],int N[][10],int M[10][10],int W[1][10],int *n,int *m){
int i,j;
printf("\n Enter total no. of processes : ");
scanf("%d",n);
printf("\n Enter total no. of resources : ");
scanf("%d",m);
for(i=0;i<*n;i++){
printf("\n Process %d\n",i+1);
for(j=0;j<*m;j++){
printf(" Allocation for resource %d : ",j+1);
scanf("%d",&A[i][j]);
printf(" Maximum for resource %d : ",j+1);
scanf("%d",&M[i][j]);
}
}
printf("\n Available resources : \n");
for(i=0;i<*m;i++){
printf(" Resource %d : ",i+1);
scanf("%d",&W[0][i]);
}
for(i=0;i<*n;i++)
for(j=0;j<*m;j++)
N[i][j]=M[i][j]-A[i][j];
printf("\n Allocation Matrix");
print(A,*n,*m);
printf("\n Maximum Requirement Matrix");
print(M,*n,*m);
printf("\n Need Matrix");
print(N,*n,*m);
}
int banker(int A[][10],int N[][10],int W[1][10],int n,int m){
int j,i,a[10];
j=safety(A,N,W,n,m,a);
if(j != 0 ){
printf("\n\n");
for(i=0;i<n;i++)
printf(" P%d ",a[i]);
printf("\n A safety sequence has been detected.\n");
return 1;
}else{
printf("\n Deadlock has occured.\n");
return 0;
}
}
int main(){
int ret;
int A[10][10];
int M[10][10];
int N[10][10];
int W[1][10];
int n,m,pid,ch;
printf("\n DEADLOCK AVOIDANCE USING BANKER'S ALGORITHM\n");
accept(A,N,M,W,&n,&m);
ret=banker(A,N,W,n,m);
if(ret !=0 ){
printf("\n Do you want make an additional request ? (1=Yes|0=No)");
scanf("%d",&ch);
if(ch == 1){
printf("\n Enter process no. : ");
scanf("%d",&pid);
res_request(A,N,W,pid-1,m);
ret=banker(A,N,W,n,m);
if(ret == 0 )
exit(0);
}
}else
exit(0);
return 0;
}
ReplyDeleteHELLO WORLD MPI:
#include
#include
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
ass1bankers algorithm
ReplyDelete#include
#define MAX 10
int m,n,total[MAX],avail[MAX],alloc[MAX][MAX],
max[MAX][MAX],need[MAX][MAX],work[MAX],finish[MAX],
seq[MAX],request[MAX];
void accept()
{
int i,j;
printf("Enter no.of process:");
scanf("%d",&n);
printf("Enter no.of resource types:");
scanf("%d",&m);
printf("Enter total no.of resources of each resource type:\n");
for(i=0;iwork[j])
break;
}
if(j==m) return i;
}
i=(i+1)%n;
}while(i!=s);
return -1;
}
void banker()
{
int i,j,k=0;
for(i=0;ineed[pno][j])
break;
}
if(j==m)
{
for(j=0;javail[j])
break;
}
if(j==m)
{
for(j=0;j<m;j++)
{
avail[j]-=request[j];
alloc[pno][j]+=request[j];
need[pno][j]-=request[j];
print();
banker();
}
}
else
printf("Process P%d must wait.\n",pno);
}
else
printf("Process P%d has exceeded its maximum claim\n",pno);
return 0;
}
sequencial
ReplyDelete#include
#include
#include
#define MAX 200
typedef struct dir
{
char fname[20];
int start;
struct dir *next;
}NODE;
NODE *first,*last;
int n,fb,bit[MAX];
void init()
{
int i;
printf("Enter total no.of disk blocks:");
scanf("%d",&n);
fb = n;
for(i=0;i<10;i++)
{
int k = rand()%n;
if(bit[k]!=-2)
{
bit[k]=-2;
fb--;
}
}
}
void show_bitvector()
{
int i;
for(i=0;ifname);
i = p->start;
while(i!=-1)
{
printf("%d->",i);
i=bit[i];
}
printf("NULL\n");
p=p->next;
}
}
void create()
{
NODE *p;
char fname[20];
int i,j,nob;
printf("Enter file name:");
scanf("%s",fname);
printf("Enter no.of blocks:");
scanf("%d",&nob);
if(nob>fb)
{
printf("Failed to create file %s\n",fname);
return;
}
for(i=0;ifname,fname);
p->start=i;
p->next=NULL;
if(first==NULL)
first=p;
else
last->next=p;
last=p;
fb-=nob;
j=i+1;
nob--;
while(nob>0)
{
if(bit[j]==0)
{
bit[i]=j;
i=j;
nob--;
}
j++;
}
bit[i]=-1;
printf("File %s created successully.\n",fname);
}
void delete()
{
char fname[20];
NODE *p,*q;
int nob=0,i,j;
printf("Enter file name to be deleted:");
scanf("%s",fname);
p = q = first;
while(p!=NULL)
{
if(strcmp(p->fname,fname)==0)
break;
q=p;
p=p->next;
}
if(p==NULL)
{
printf("File %s not found.\n",fname);
return;
}
i = p->start;
while(i!=-1)
{
nob++;
j = i;
i = bit[i];
bit[j] = 0;
}
fb+=nob;
if(p==first)
first=first->next;
else if(p==last)
{
last=q;
last->next=NULL;
}
else
q->next = p->next;
free(p);
printf("File %s deleted successfully.\n",fname);
}
int main()
{
int ch;
init();
while(1)
{
printf("1.Show bit vector\n");
printf("2.Create new file\n");
printf("3.Show directory\n");
printf("4.Delete file\n");
printf("5.Exit\n");
printf("Enter your choice (1-5):");
scanf("%d",&ch);
switch(ch)
{
case 1:
show_bitvector();
break;
case 2:
create();
break;
case 3:
show_dir();
break;
case 4:
delete();
break;
case 5:
exit(0);
}
}
return 0;
}