Posts

OPERATING SYSTM’s ALGORITHM (In LINUX OS) - DINING PHILOSOPHERS PROBLEM

DINING PHILOSOPHERS PROBLEM PROGRAM: #include<stdio.h> int i,j,pn,ch,k,l; char state[5]; int thinking=0; int hungry=1; int eating=2; main() { do { printf(“\nEnter the choice\n”); printf(“1.Pick up\n2.Put down\n3.Exit\n”); scanf(“%d”,&ch); switch(ch) { case 1: printf(“Enter the philosopher number”); scanf(“%d”,&pn); pickup(pn); break; case 2: printf(“Enter the philosopher number”); scanf(“%d”,&pn); putdown(pn); break; } } while(ch!=3); } int pickup(int i) { state[i]=hungry; test(i); if(state[i]!=eating) printf(“Philosopher %d has to wait\n’,i); } int putdown(int k) { state[k]=thinking; test((k+4)%5); test((k+1)%5); } int test(int l) { if(state[(l+4)%5]!=eating&&state[l]==hungry&&state[(l+1)%5!=eating) { state[l]=eating; printf(“Philosopher   %d can eat\n”,l); } } OUTPUT: Enter the choice 1.Pick up 2.Put down 3.Exit 1 Enter the philosopher number 1 Philosopher 1can eat

OPERATING SYSTM’s ALGORITHM (In LINUX OS) - FIRST FIT, BEST FIT, WORST FIT ALGORITHM

FIRST FIT, BEST FIT, WORST FIT ALGORITHM PROGRAM: #include<stdio.h> int mem[20],proc[20],bp[20],bm[20],cm[20],cp[20],ms,ps,i,j,ch,y; main() {             printf(“\nEnter the number of memory segments”);             scanf(“%d”,&ms);             printf(“\nEnter the memory segment”);             for(i=0;i<ms;i++)             {                         scanf(“%d”,&mem[i]);                         bm[i]=cm[i]=mem[i];             }             printf(“\nEnter the number of process”);             scanf(“%d”,&ps);             printf(“\nEnter the memory space for process”);             for(i=0;i<ps;i++)             {                         scanf(“%d”,&proc[i]);                         bp[i]=op[i]=proc[i];             }             do             {                         printf(“\nEnter the choice”); printf(“\n1.First fit\n2.Best fit\n3.Worst fit\n4.Exit”); scanf(“%d”,&ch); switch(ch