├── Bash_Script ├── touch.sh ├── alpha.sh ├── name.sh ├── lab5.sh ├── ctof.sh ├── odd.sh ├── lab2.sh ├── lab3.sh ├── lab1.sh ├── string.sh ├── operations.sh ├── average.sh ├── bash.sh ├── fibonacci.sh ├── largest.sh ├── arop.sh └── shapes.sh ├── Micro_Project ├── micro └── micro.c ├── System_Call ├── syscall6.c ├── syscall3.c ├── syscall1.c ├── files.c ├── directory.c ├── syscall4.c ├── cat.c ├── syscall2.c ├── syscall5.c └── copyfile.c ├── README.md ├── Shared_Memory ├── fact_print.c └── fact_read.c ├── Disk_Scheduling ├── fcfs.c ├── scan.c └── cscan.c ├── Page_Replacement ├── lru.c ├── fifo.c └── lfu.c ├── Message_Passing_Model └── PCP.c ├── Scheduling ├── Non_Preemptive │ ├── sjf.c │ ├── fcfs.c │ └── priority.c └── Preemptive │ └── roundrobin.c ├── MEMORY ALLOCATION SCHEMES └── memory.c └── Deadlock_Avoidance └── bankers.c /Bash_Script/touch.sh: -------------------------------------------------------------------------------- 1 | touch file.txt 2 | -------------------------------------------------------------------------------- /Bash_Script/alpha.sh: -------------------------------------------------------------------------------- 1 | a=$1 2 | b=$2 3 | c=$3 4 | { echo $a;echo $b;echo $c;} | sort 5 | -------------------------------------------------------------------------------- /Bash_Script/name.sh: -------------------------------------------------------------------------------- 1 | echo -n "Enter your name:" 2 | read name 3 | echo "Hello $name" 4 | -------------------------------------------------------------------------------- /Bash_Script/lab5.sh: -------------------------------------------------------------------------------- 1 | echo "a:" 2 | read a 3 | ((b=a*9/5)) 4 | ((b=b+32)) 5 | echo "b:$b" 6 | -------------------------------------------------------------------------------- /Bash_Script/ctof.sh: -------------------------------------------------------------------------------- 1 | echo -n "a:" 2 | read a 3 | ((b=a*9/5)) 4 | ((b=b+32)) 5 | echo "b:$b" 6 | -------------------------------------------------------------------------------- /Micro_Project/micro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoelBobyM/S4-OS-LAB-KTU/HEAD/Micro_Project/micro -------------------------------------------------------------------------------- /Bash_Script/odd.sh: -------------------------------------------------------------------------------- 1 | for((i=0;i<100;i++)) 2 | do 3 | if((i%2!=0)) 4 | then 5 | echo $i 6 | fi 7 | done 8 | -------------------------------------------------------------------------------- /Bash_Script/lab2.sh: -------------------------------------------------------------------------------- 1 | a=$1 2 | b=$2 3 | while((b!=0)) 4 | do 5 | ((t=b)) 6 | ((b=a%b)) 7 | ((a=t)) 8 | done 9 | echo $a 10 | 11 | -------------------------------------------------------------------------------- /Bash_Script/lab3.sh: -------------------------------------------------------------------------------- 1 | read a 2 | fact=1 3 | i=1 4 | while((i<=a)) 5 | do 6 | ((fact=fact*i)) 7 | ((i=i+1)) 8 | done 9 | echo $fact 10 | 11 | -------------------------------------------------------------------------------- /Bash_Script/lab1.sh: -------------------------------------------------------------------------------- 1 | a=$1 2 | b=$2 3 | while((a!=b)) 4 | do 5 | if((a>b)) 6 | then 7 | ((a=a-b)) 8 | else 9 | ((b=b-a)) 10 | fi 11 | done 12 | echo $a 13 | -------------------------------------------------------------------------------- /System_Call/syscall6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | fork(); 6 | fork(); 7 | fork(); 8 | fork(); 9 | printf("Hello World\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Bash_Script/string.sh: -------------------------------------------------------------------------------- 1 | echo -n "Enter first string:" 2 | read s1 3 | echo -n "Enter second string:" 4 | read s2 5 | echo -n "Enter third string:" 6 | read s3 7 | { echo $s1;echo $s2;echo $s3;} | sort 8 | 9 | -------------------------------------------------------------------------------- /System_Call/syscall3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { 6 | struct stat buf; 7 | stat("./hello.c",&buf); 8 | printf("%d\n",buf.st_mode); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Bash_Script/operations.sh: -------------------------------------------------------------------------------- 1 | a=$1 2 | b=$2 3 | ((sum=a+b)) 4 | echo "Sum= $sum" 5 | ((diff=a-b)) 6 | echo "Difference= $diff" 7 | ((prod=a*b)) 8 | echo "Product= $prod" 9 | ((div=a/b)) 10 | echo "Quotient= $div" 11 | 12 | -------------------------------------------------------------------------------- /Bash_Script/average.sh: -------------------------------------------------------------------------------- 1 | echo -n "Enter no:of integers:" 2 | read n 3 | sum=0 4 | for((i=1;i<=n;i++)) 5 | do 6 | echo -n "Enter number $i:" 7 | read num 8 | ((sum=sum+num)) 9 | done 10 | ((avg=sum/n)) 11 | echo "Average=$avg" 12 | -------------------------------------------------------------------------------- /Bash_Script/bash.sh: -------------------------------------------------------------------------------- 1 | dir="bash" 2 | if [ -d $dir ] 3 | then 4 | echo "directory exists" 5 | else 6 | echo "directory doesnot exist" 7 | echo "creating directory..." 8 | mkdir $dir 9 | echo "directory created" 10 | fi 11 | ls 12 | 13 | -------------------------------------------------------------------------------- /System_Call/syscall1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | pid_t p; 6 | p=fork(); 7 | if(p==0) 8 | { 9 | printf("I am child\n"); 10 | } 11 | else if(p>0) 12 | { 13 | printf("I am parent\n"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Bash_Script/fibonacci.sh: -------------------------------------------------------------------------------- 1 | echo -n "enter a number:" 2 | read n 3 | 4 | a=0 5 | b=1 6 | ((c=a+b)) 7 | ((n=n-2)) 8 | echo "series:" 9 | echo $a 10 | echo $b 11 | for((i=1;i<=n;i++)) 12 | do 13 | echo $c 14 | ((a=b)) 15 | ((b=c)) 16 | ((c=a+b)) 17 | done 18 | -------------------------------------------------------------------------------- /System_Call/files.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { 6 | DIR *d; 7 | struct dirent *de; 8 | d=opendir("."); 9 | while(de=readdir(d)) 10 | { 11 | if(de->d_type == DT_REG) 12 | { 13 | printf("%s\n",de->d_name); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # S4-OS-LAB-KTU 2 | A repository to store efficient Operating System Lab Programs (2019 Scheme KTU) 3 | * Find most of the OS LAB programs through this repository. 4 | * If you have ability then make the already existing codes simpler and efficient 5 | * You're also free to add new programs 6 | 7 | ### BEST WISHES 8 | -------------------------------------------------------------------------------- /System_Call/directory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { 6 | DIR *d; 7 | struct dirent *de; 8 | d=opendir("."); 9 | while(de=readdir(d)) 10 | { 11 | if(de->d_type == DT_DIR ) 12 | { 13 | printf("%s\n",de->d_name); 14 | } 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /System_Call/syscall4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void main() 6 | { 7 | DIR *d; 8 | d=opendir("fisat"); 9 | if(d==NULL) 10 | { 11 | printf("Directory doesnot exist\n"); 12 | } 13 | else 14 | { 15 | printf("Directory exist\n"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Micro_Project/micro.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { 6 | pid_t pid; 7 | printf("ENTER THE PID OF PROCESS TO BE KILLED : "); 8 | scanf("%d",&pid); 9 | int a = kill(pid, SIGKILL); 10 | if(a==0) 11 | printf("PROCESS SUCESSFULLY KILLED\n"); 12 | else 13 | printf("ERROR WHILE KILL OPERATION : %d\n",a); 14 | } 15 | -------------------------------------------------------------------------------- /Bash_Script/largest.sh: -------------------------------------------------------------------------------- 1 | echo -n "enter number 1:" 2 | read n1 3 | echo -n "enter number 2:" 4 | read n2 5 | echo -n "enter number 3:" 6 | read n3 7 | if ((n1>n2)) && ((n1>n3)) 8 | then 9 | echo $n1 "is the largest number" 10 | elif ((n1n3)) 11 | then 12 | echo $n2 "is the largest number" 13 | elif ((n3>n1)) && ((n3>n2)) 14 | then 15 | echo $n3 "is the largest number" 16 | fi 17 | -------------------------------------------------------------------------------- /System_Call/cat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main(int argc, char *argv[]) 5 | { 6 | if(argc != 2) 7 | { 8 | printf("Argument Error.\n"); 9 | return; 10 | } 11 | char *file= argv[1]; 12 | pid_t p=fork(); 13 | int status; 14 | if(p==0) 15 | { 16 | execl("/usr/bin/cat","cat",file,NULL); 17 | } 18 | else 19 | { 20 | wait(&status); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Bash_Script/arop.sh: -------------------------------------------------------------------------------- 1 | echo -n "enter first number:" 2 | read a 3 | echo -n "enter second number:" 4 | read b 5 | echo -n "enter operator:" 6 | read op 7 | if [[ $op == "+" ]] 8 | then 9 | ((c=a+b)) 10 | elif [[ $op == "-" ]] 11 | then 12 | ((c=a-b)) 13 | elif [[ $op == "*" ]] 14 | then 15 | ((c=a*b)) 16 | elif [[ $op == "/" ]] 17 | then 18 | ((c=a/b)) 19 | elif [[ $op == "%" ]] 20 | then 21 | ((c=a%b)) 22 | fi 23 | echo "result=$c" 24 | -------------------------------------------------------------------------------- /System_Call/syscall2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | pid_t p; 6 | int i; 7 | p=fork(); 8 | if(p==0) 9 | { 10 | printf("In child process:\n"); 11 | for(i=1;i<=10;i++) 12 | { 13 | printf("%d ",i); 14 | } 15 | printf("\n"); 16 | } 17 | else if(p>0) 18 | { 19 | printf("In parent process:\n"); 20 | for(i=1;i<=10;i++) 21 | { 22 | printf("%d ",i); 23 | } 24 | printf("\n"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /System_Call/syscall5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | pid_t p; 6 | p=fork(); 7 | if(p==0) 8 | { 9 | printf("In child process:\n"); 10 | printf("PID of parent process:%d",getppid()); 11 | printf("\nPID of process:%d",getpid()); 12 | } 13 | else if(p>0) 14 | { 15 | printf("In parent process:\n"); 16 | printf("PID of parent process:%d",getppid()); 17 | printf("\nPID of process:%d",getpid()); 18 | } 19 | printf("\n"); 20 | } 21 | -------------------------------------------------------------------------------- /Shared_Memory/fact_print.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | void main() 8 | { 9 | int i,fact; 10 | int fd = shm_open("/os_lab",O_RDONLY,0666); 11 | int *data = (int *)mmap(NULL,sizeof(int),PROT_READ,MAP_SHARED,fd,0); 12 | int a = data[0]; 13 | for(i=1,fact=1;i<=a;fact*=i,i++); 14 | printf("FACTORIAL OF %d IS : %d\n",a,fact); 15 | munmap(data,sizeof(int)); 16 | close(fd); 17 | shm_unlink("/os_lab"); 18 | } 19 | -------------------------------------------------------------------------------- /Shared_Memory/fact_read.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | void main() 8 | { 9 | int fd = shm_open("/os_lab",O_CREAT|O_RDWR,0666); 10 | int ft = ftruncate(fd,sizeof(int)); 11 | if (ft==-1) 12 | { 13 | printf("ERROR!!!\n"); 14 | } 15 | else 16 | { 17 | printf("SHARED MEMORY CREATED\n"); 18 | int *data = (int *)mmap(NULL,sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); 19 | printf("ENTER THE NUMBER : "); 20 | scanf("%d",&data[0]); 21 | munmap(data,sizeof(int)); 22 | } 23 | close(fd); 24 | } 25 | -------------------------------------------------------------------------------- /Disk_Scheduling/fcfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int tr[20],cr,n,i,sum=0,new; 6 | printf("ENTER THE NUMBER OF TRACKS : "); 7 | scanf("%d",&n); 8 | printf("ENTER THE HEAD POINTER POSITION : "); 9 | scanf("%d",&cr); 10 | printf("ENTER THE TRACKS TO BE TRAVERSED : "); 11 | for(i=0;i ",tr[i]); 26 | printf("\b\b\b. \nTOTAL HEAD MOVEMENTS : %d\n",sum); 27 | } 28 | -------------------------------------------------------------------------------- /Bash_Script/shapes.sh: -------------------------------------------------------------------------------- 1 | echo "1.Area of circle" 2 | echo "2.Circumference of circle" 3 | echo "3.Area of reactangle" 4 | echo "4.Area of square" 5 | echo -n "Enter choice:" 6 | read ch 7 | 8 | if((ch==1)) 9 | then 10 | echo -n "Enter Radius:" 11 | read r 12 | ((a=((22/7))*r*r)) 13 | echo "Area=$a" 14 | elif((ch==2)) 15 | then 16 | echo -n "Enter Radius:" 17 | read r 18 | ((a=2*22/7*r)) 19 | echo "Circumference=$a" 20 | elif((ch==3)) 21 | then 22 | echo -n "Enter length:" 23 | read l 24 | echo -n "Enter breadth:" 25 | read b 26 | ((a=l*b)) 27 | echo "Area of rectangle=$a" 28 | elif((ch==4)) 29 | then 30 | echo -n "Enter side:" 31 | read s 32 | ((a=s*s)) 33 | echo "Area of square=$a" 34 | else 35 | echo "Invalid Choice" 36 | fi 37 | -------------------------------------------------------------------------------- /System_Call/copyfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | void main(int argc, char *argv[]) 8 | { 9 | if(argc != 3) 10 | { 11 | printf("INVALID NUMBER OF ARGUMENTS.\n"); 12 | exit(0); 13 | } 14 | char *file1 = argv[1]; 15 | char *file2 = argv[2]; 16 | char wbuf[100] = "START\n"; 17 | char rbuf[100]; 18 | int fd1 = open(file1,O_RDONLY); 19 | int fd2 = open(file2,O_CREAT|O_WRONLY,S_IRWXU); 20 | write(fd2,wbuf,strlen(wbuf)); 21 | read(fd1,rbuf,100); 22 | write(fd2,rbuf,strlen(rbuf)); 23 | strcpy(wbuf,"STOP"); 24 | write(fd2,wbuf,strlen(wbuf)); 25 | printf("SUCCESSFULLY COPIED\n"); 26 | close(fd1); 27 | close(fd2); 28 | } 29 | -------------------------------------------------------------------------------- /Page_Replacement/lru.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct frames 3 | { 4 | int content,count; 5 | }frame[100]; 6 | void main() 7 | { 8 | int i,j,k,p,f,page[100],cnt=1,min,pf=0,id=0; 9 | printf("ENTER THE NUMBER OF PAGES : "); 10 | scanf("%d",&p); 11 | printf("ENTER THE REFERENCING STRING : "); 12 | for(i=0;i 2 | int n,m,i,j,h,p,temp,k,total=0; 3 | int t[100],a[100],diff; 4 | void main() 5 | { 6 | printf("ENTER THE NUMBER OF TRACKS : "); 7 | scanf("%d",&n); 8 | printf("ENTER THE HEAD POINTER POSITION : "); 9 | scanf("%d",&h); 10 | printf("ENTER THE TRACKS TO BE TRAVERSED : "); 11 | for(i=0;it[j+1]) 24 | { 25 | temp=t[j]; 26 | t[j]=t[j+1]; 27 | t[j+1]=temp; 28 | } 29 | } 30 | } 31 | for(i=0;i=0;i--,p++) 42 | { 43 | a[p]=t[i]; 44 | } 45 | for(i=k+1;i=0;i--,p++) 57 | { 58 | a[p]=t[i]; 59 | } 60 | } 61 | printf("TRAVERSED ORDER : "); 62 | for(i=0;i ",a[i]); 65 | } 66 | for(total=0,j=0;ja[j+1]) 70 | { 71 | diff=a[j]-a[j+1]; 72 | } 73 | else 74 | { 75 | diff=a[j+1]-a[j]; 76 | } 77 | total=total+diff; 78 | } 79 | printf("\b\b\b. \nTOTAL HEAD MOVEMENTS : %d\n",total); 80 | } 81 | -------------------------------------------------------------------------------- /Disk_Scheduling/cscan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int n,m,i,j,h,p,temp,k,total=0; 3 | int t[100],a[100],diff[100]; 4 | void main() 5 | { 6 | printf("ENTER THE NUMBER OF TRACKS : "); 7 | scanf("%d",&n); 8 | printf("ENTER THE HEAD POINTER POSITION : "); 9 | scanf("%d",&h); 10 | printf("ENTER THE TRACKS TO BE TRAVERSED : "); 11 | for(i=0;it[j+1]) 24 | { 25 | temp=t[j]; 26 | t[j]=t[j+1]; 27 | t[j+1]=temp; 28 | } 29 | } 30 | } 31 | for(i=0;i=0;i--,p++) 42 | { 43 | a[p]=t[i]; 44 | } 45 | for(i=n-1;i>k;i--,p++) 46 | { 47 | a[p]=t[i]; 48 | } 49 | } 50 | else 51 | { 52 | for(i=k;i ",a[i]); 65 | } 66 | for(total=0,j=0;ja[j+1]) 70 | { 71 | diff=a[j]-a[j+1]; 72 | } 73 | else 74 | { 75 | diff=a[j+1]-a[j]; 76 | } 77 | total=total+diff; 78 | } 79 | printf("\b\b\b. \nTOTAL HEAD MOVEMENTS : %d\n",total); 80 | } 81 | -------------------------------------------------------------------------------- /Page_Replacement/fifo.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int i,j,n,m,fnd,pg[100],fr[100],k=0,cnt=0; 5 | printf("ENTER THE NUMBER OF PAGES : "); 6 | scanf("%d",&n); 7 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | sem_t mutex,full,empty; 6 | int buffer[5],put=0,get=0,item=1,pro[20],con[20],gitem; 7 | void *producer(void *arg) 8 | { 9 | do 10 | { 11 | sem_wait(&empty); 12 | sem_wait(&mutex); 13 | buffer[put%5]=item; 14 | 15 | int *myid = (int *)arg; 16 | printf("PRODUCER %d PRODUCES %d ITEM => BUFFER[%d] : %d\n",*myid,buffer[put%5],put%5,item); 17 | item++; 18 | put++; 19 | sem_post(&mutex); 20 | sem_post(&full); 21 | sleep(3); 22 | } 23 | while(1); 24 | } 25 | void *consumer(void *arg) 26 | { 27 | do 28 | { 29 | sem_wait(&full); 30 | sem_wait(&mutex); 31 | gitem=buffer[get%5]; 32 | int *myid = (int *)arg; 33 | printf("CONSUMER %d CONSUMES %d ITEM OF BUFFER[%d]\n",*myid,gitem,get%5); 34 | get++; 35 | sem_post(&mutex); 36 | sem_post(&empty); 37 | sleep(2); 38 | } 39 | while(1); 40 | } 41 | void main() 42 | { 43 | int p,c,j,k; 44 | pthread_t a[10],b[10]; 45 | sem_init(&mutex,0,1); 46 | sem_init(&full,0,0); 47 | sem_init(&empty,0,5); 48 | printf("ENTER THE NUMBER OF PRODUCERS : "); 49 | scanf("%d",&p); 50 | printf("ENTER THE NUMBER OF CONSUMERS : "); 51 | scanf("%d",&c); 52 | for(j=0;j 2 | struct frame 3 | { 4 | int content; 5 | int freq; 6 | int cnt; 7 | }frames[100]; 8 | void main() 9 | { 10 | int i,j,pg,fr,cnt,pf,min,page[100],id=0; 11 | printf("ENTER THE NUMBER OF PAGES : "); 12 | scanf("%d",&pg); 13 | printf("ENTER THE REFERENCING STRING : "); 14 | for(i=0;i frames[j].freq) 54 | { 55 | min = j; 56 | } 57 | else if(frames[min].freq == frames[j].freq && frames[min].cnt > frames[j].cnt) 58 | { 59 | min = j; 60 | } 61 | } 62 | frames[min].content = page[i]; 63 | frames[min].freq = 1; 64 | frames[min].cnt = cnt++; 65 | } 66 | pf++; 67 | } 68 | for(j=0;j 2 | #include 3 | struct process 4 | { 5 | char name[20]; 6 | int at,tt,bt,wt,status,ct; 7 | }p[20],temp; 8 | struct done 9 | { 10 | char name[20]; 11 | int st,ct; 12 | }d[20]; 13 | void main() 14 | { 15 | int n,i,j,ls,min,fnd,num,idle; 16 | float twt=0.0,ttt=0.0; 17 | printf("ENTER THE NUMBER OF PROCESSES : "); 18 | scanf("%d",&n); 19 | for(i=0;i=p[j].at && p[j].status==0) 35 | { 36 | if(fnd==0) 37 | { 38 | min = j; 39 | fnd = 1; 40 | } 41 | else if(fnd!=0 && p[min].bt>p[j].bt) 42 | { 43 | min = j; 44 | } 45 | } 46 | } 47 | if(idle==0 && fnd==0) 48 | { 49 | strcpy(d[num].name,"Idle"); 50 | d[num].st = i; 51 | i++; 52 | idle = 1; 53 | } 54 | else if(fnd==1) 55 | { 56 | if(idle==1) 57 | { 58 | d[num].ct = i; 59 | num++; 60 | idle = 0; 61 | } 62 | strcpy(d[num].name,p[min].name); 63 | p[min].status =1; 64 | d[num].st = i; 65 | d[num].ct = i + p[min].bt; 66 | i = d[num].ct; 67 | p[min].ct = d[num].ct; 68 | p[min].tt = p[min].ct - p[min].at; 69 | p[min].wt = p[min].tt - p[min].bt; 70 | num++; 71 | ls++; 72 | } 73 | else 74 | { 75 | i++; 76 | } 77 | } 78 | printf("\nPROCESS NAME\tCOMPLETION TIME (ms)\tWAITING TIME (ms)\tTURNAROUND TIME (ms)\n\n"); 79 | for(i=0;i 2 | #include 3 | struct process 4 | { 5 | char name[20]; 6 | int at,tt,bt,wt,ct,status; 7 | }p[20],temp; 8 | struct done 9 | { 10 | char name[20]; 11 | int st,ct; 12 | }d[20]; 13 | void main() 14 | { 15 | int i,j,n,num,idle=0; 16 | float avwt=0; 17 | float avtt=0; 18 | printf("ENTER THE NUMBER OF PROCESSES : "); 19 | scanf("%d",&n); 20 | for(i=0;i p[j+1].at) 36 | { 37 | temp = p[j]; 38 | p[j] = p[j+1]; 39 | p[j+1] = temp; 40 | } 41 | } 42 | } 43 | for(i=0,j=0,num=0;j 2 | #include 3 | struct process 4 | { 5 | char name[20]; 6 | int at,tt,bt,wt,status,ct,pr; 7 | }p[20],temp; 8 | struct done 9 | { 10 | char name[20]; 11 | int st,ct; 12 | }d[20]; 13 | void main() 14 | { 15 | int n,i,j,ls,min,fnd,num,idle; 16 | float twt=0.0,ttt=0.0; 17 | printf("ENTER THE NUMBER OF PROCESSES : "); 18 | scanf("%d",&n); 19 | for(i=0;i=p[j].at && p[j].status==0) 37 | { 38 | if(fnd==0) 39 | { 40 | min = j; 41 | fnd = 1; 42 | } 43 | else if((p[min].pr>p[j].pr)||(p[min].pr==p[j].pr && p[min].at>p[j].at)) 44 | { 45 | min = j; 46 | } 47 | } 48 | } 49 | if(idle==0 && fnd==0) 50 | { 51 | strcpy(d[num].name,"Idle"); 52 | d[num].st = i; 53 | i++; 54 | idle = 1; 55 | } 56 | else if(fnd==1) 57 | { 58 | if(idle==1) 59 | { 60 | d[num].ct = i; 61 | num++; 62 | idle = 0; 63 | } 64 | strcpy(d[num].name,p[min].name); 65 | p[min].status =1; 66 | d[num].st = i; 67 | d[num].ct = i + p[min].bt; 68 | i = d[num].ct; 69 | p[min].ct = d[num].ct; 70 | p[min].tt = p[min].ct - p[min].at; 71 | p[min].wt = p[min].tt - p[min].bt; 72 | num++; 73 | ls++; 74 | } 75 | else 76 | { 77 | i++; 78 | } 79 | } 80 | printf("\nPROCESS NAME\tCOMPLETION TIME (ms)\tWAITING TIME (ms)\tTURNAROUND TIME (ms)\n\n"); 81 | for(i=0;i 2 | void firstfit(int p_size[],int n,int m_size[],int m) 3 | { 4 | printf("\t\tFIRST FIT \n"); 5 | int i,j,flag,psize[100],msize[100]; 6 | for(i=0;i=psize[i]) 20 | { 21 | printf("%d ALLOCATED IN %d MEMORY BLOCK",psize[i],msize[j]); 22 | msize[j] = msize[j]-psize[i]; 23 | printf(" => %d SPACE REMAINING \n",msize[j]); 24 | flag=1; 25 | break; 26 | } 27 | } 28 | if(flag==0) 29 | { 30 | printf("%d CANNOT BE ALLOCATED \n",psize[i]); 31 | } 32 | } 33 | } 34 | void worstfit(int p_size[],int n,int m_size[],int m) 35 | { 36 | printf("\t\tWORST FIT \n"); 37 | int i,j,max,loc,psize[100],msize[100]; 38 | for(i=0;imax) 53 | { 54 | max = msize[j]; 55 | loc = j; 56 | } 57 | } 58 | if(max>=psize[i]) 59 | { 60 | printf("%d ALLOCATED IN %d MEMORY BLOCK",psize[i],msize[loc]); 61 | msize[loc] = msize[loc]-psize[i]; 62 | printf(" => %d SPACE REMAINING \n",msize[loc]); 63 | } 64 | else 65 | { 66 | printf("%d CANNOT BE ALLOCATED \n",psize[i]); 67 | } 68 | } 69 | } 70 | void bestfit(int p_size[],int n,int m_size[],int m) 71 | { 72 | printf("\t\tBEST FIT \n"); 73 | int i,j,max,loc,psize[100],msize[100]; 74 | for(i=0;i=psize[i]) 88 | { 89 | if(loc == -1) 90 | { 91 | loc = j; 92 | } 93 | else if(msize[loc]>msize[j]) 94 | { 95 | loc = j; 96 | } 97 | } 98 | } 99 | if(loc != -1) 100 | { 101 | printf("%d ALLOCATED IN %d MEMORY BLOCK",psize[i],msize[loc]); 102 | msize[loc] = msize[loc]-psize[i]; 103 | printf(" => %d SPACE REMAINING \n",msize[loc]); 104 | } 105 | else 106 | { 107 | printf("%d CANNOT BE ALLOCATED \n",psize[i]); 108 | } 109 | } 110 | } 111 | void main() 112 | { 113 | int i,p_size[100],m_size[100],n,m; 114 | printf("ENTER THE NUMBER OF PROCESS : "); 115 | scanf("%d",&n); 116 | printf("ENTER THE ARRAY OF PROCESS : "); 117 | for(i=0;i 2 | #include 3 | int q[100],front=-1,rear=-1; 4 | struct process 5 | { 6 | char name[20]; 7 | int at,tt,bt,wt,status,left,ct; 8 | }p[20],temp; 9 | struct done 10 | { 11 | char name[20]; 12 | int st,ct; 13 | }d[20]; 14 | void enqueue(int j) 15 | { 16 | if(front==-1 && rear==-1) 17 | { 18 | front++; 19 | } 20 | rear++; 21 | q[rear] = j; 22 | } 23 | int dequeue() 24 | { 25 | int item; 26 | item = q[front]; 27 | if(front == rear) 28 | { 29 | front = -1; 30 | rear = -1; 31 | } 32 | else 33 | { 34 | front++; 35 | } 36 | return(item); 37 | } 38 | void main() 39 | { 40 | int n,i,j,idle=0,k,num,ls,t; 41 | float avwt=0,avtt=0; 42 | printf("ENTER THE NUMBER OF PROCESSES : "); 43 | scanf("%d",&n); 44 | for(i=0;it) 99 | { 100 | d[num].ct = i+t; 101 | i = d[num].ct; 102 | p[k].left = p[k].left-t; 103 | num++; 104 | for(j=0;j 2 | #include 3 | #include 4 | 5 | int avail[100]; 6 | int resmax[100]; 7 | int maxalloc[100]; 8 | int req[100]; 9 | struct process 10 | { 11 | char name[100]; 12 | int max[100]; 13 | int alloc[100]; 14 | int need[100]; 15 | int done; 16 | }p[20],temp; 17 | void main() 18 | { 19 | int i,j,r,pr,flag,ls,ml=0,g=0,id; 20 | char name[100],str[100] = ""; 21 | printf("ENTER THE NUMBER OF RESOURCES : "); 22 | scanf("%d",&r); 23 | printf("MAXIMUM RESOURCE COUNT FOR : \n"); 24 | for(j=0;j=p[i].need[j]) 116 | { 117 | flag++; 118 | } 119 | } 120 | if(flag == r && p[i].done == 0) 121 | { 122 | p[i].done = ls+1; 123 | for(ml=0,j=0;j