#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<sys/types.h>
struct Node{
int p_id;
int arr_hr;
int arr_min;
int exe_time;
};
int main(){
int i,j,no_of_processes;
struct Node *Queue,temp;
printf("\n---> First Come First Serve Scheduling <---\n");
printf("Enter no. of Processes:");
scanf("%d",&no_of_processes);
Queue=malloc(no_of_processes);
for(i=0;i<no_of_processes;i++){
printf("Give Process#%d id :\n",i+1);
scanf("%d",&Queue[i].p_id);
printf("Give Arrival Hour
(0~23):\n");
scanf("%d",&Queue[i].arr_hr);
printf("Give Arrival Minute :\n");
scanf("%d",&Queue[i].arr_min);
printf("Give Execution Time (in
secs.):\n");
scanf("%d",&Queue[i].exe_time);
}
for(i=0;i<no_of_processes;i++){
for(j=0;j<no_of_processes-i-1;j++)
if(Queue[j].arr_hr>Queue[j+1].arr_hr || (Queue[j].arr_hr==Queue[j+1].arr_hr && Queue[j].arr_min>Queue[j+1].arr_min)){
temp=Queue[j];
Queue[j]=Queue[j+1];
Queue[j+1]=temp;
}
}
for(i=0;i<no_of_processes;i++){
printf("--> PROCESS with Process ID#%d <--\n",Queue[i].p_id);
printf("This process arrived at %d:%d and requires %d
seconds for execution\n", Queue[i].arr_hr, Queue[i].arr_min,
Queue[i].exe_time);
seconds for execution\n", Queue[i].arr_hr, Queue[i].arr_min,
Queue[i].exe_time);
printf("Execution in Progress\n\n");
for(j=0;j<Queue[i].exe_time;j++){
sleep(1);
printf("*");
}
printf("\n\nPROCESS FINISHED\n\n");
}
return 0;
}
No comments
Post a Comment