├── README.md
├── demo.txt
├── non-preempt-28963555
├── non-preempt-28963555.c
├── preempt-28963555
├── preempt-28963555.c
├── process-data.txt
├── process-visualiser.c
├── process-visualiser.h
├── resource
└── scheduler_pic.png
└── user_manual.txt
/README.md:
--------------------------------------------------------------------------------
1 |
Process-scheduling-simulator
2 |
Created programs to simulate two different scheduling algorithms i.e. First come, first served and Preemptive Round Robin scheduling
3 |
4 |
5 |
6 |
7 |
8 |
9 | ## Instruction
10 |
11 | ```
12 | FCFS and ROUND_ROBIN user commands
13 | Name
14 | non-preemtive-28963555 - graphic display the ROUND_ROBIN scheduler work
15 | preemtive-28963555 -graphic display the FCFS scheduler work
16 |
17 | SYNOPSIS
18 | ./non-preemtive-28963555 [fileName]
19 | or
20 | ./non-preemtive-28963555
21 | &
22 | ./preemtive-28963555 [fileName]
23 | or
24 | ./preemtive-28963555
25 | Description
26 | Graphic display of the given process in the file accordinf to the choosen scheduler
27 |
28 | commands:
29 | ./non-preemtive-28963555 [fileName], it reads the given fileName and display the graphic of the process execution using the
30 | ROUND_ROBIN scheduler
31 | Limitaion:
32 | filename should be there is same directory
33 |
34 | ./non-preemtive-28963555, it reads by default fileName "process-data.txt" and display the graphic of the process execution using the
35 | ROUND_ROBIN scheduler
36 |
37 | ./preemtive-28963555 [fileName], it reads the given fileName and display the graphic of the process execution using the
38 | FCFS scheduler
39 | Limitaion:
40 | filename should be there is same directory
41 |
42 | ./preemtive-28963555, it reads by default fileName "process-data.txt" and display the graphic of the process execution using the
43 | FCFS scheduler
44 | Overall Limitation:
45 | filename should be there and Process time should be a natural number, process name should not more than 10 characters.
46 | ```
47 |
--------------------------------------------------------------------------------
/demo.txt:
--------------------------------------------------------------------------------
1 | p1 1 1
2 | p2 3 4
3 | p3 10 1
4 | p4 14 1
5 |
--------------------------------------------------------------------------------
/non-preempt-28963555:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shouryaraj/Process-scheduling-simulator/35aca55a32e7ea5f8c2c2486d7e199f461475478/non-preempt-28963555
--------------------------------------------------------------------------------
/non-preempt-28963555.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include "process-visualiser.h"
13 |
14 | //#include "create-data.h"
15 |
16 |
17 | typedef enum
18 | {
19 | Nothing, READY, RUNNING, EXIT
20 | } process_state_t;
21 |
22 | typedef struct {
23 | char processName[11];
24 | int entryTime;
25 | int serviceTime;
26 | int remaningTime;
27 | int turnAroundTime;
28 | int waitingTime;
29 | int index; // stores the proper index according to the given file
30 | process_state_t state;
31 |
32 | } proc_data_t;
33 | proc_data_t process_array[10];
34 |
35 |
36 | int sort(proc_data_t a[], int counter);
37 | int fcfs(int number_of_process, proc_data_t array[]);
38 | int process_the_file(int infile);
39 | int storing_the_data_in_struct(int infile, int file_pointer, int end_point, int process, int count);
40 |
41 | int main(int argc, char *argv[]){
42 | int infile;
43 | int number_of_process;
44 | char *fileread_error = "Error in opening the file.\n";
45 |
46 | if(argc == 1){
47 | if ((infile = open("process-data.txt", O_RDONLY)) < 0 ){
48 | write(1, fileread_error, strlen(fileread_error));
49 | close(infile);
50 | exit(2);
51 | }
52 | }
53 | else if(argc == 2){
54 | if ((infile = open(argv[1], O_RDONLY)) < 0 ){
55 | write(1, fileread_error, strlen(fileread_error));
56 | close(infile);
57 | exit(2);
58 | }
59 |
60 | }
61 | else{
62 | printf("Too many argumnets");
63 |
64 | }
65 |
66 |
67 | number_of_process = process_the_file(infile); // Number of the process is getting return one extra
68 | //fcfs(number_of_process, process_array);umber of the process is getting return one extra
69 |
70 | fcfs(number_of_process, process_array);
71 | close(infile);
72 | exit(0);
73 |
74 | }
75 |
76 | int fcfs(int number_of_process, proc_data_t array[]){
77 |
78 |
79 | if (sizeof(proc_data_t) == 0)
80 | {
81 | return 0;
82 | }
83 |
84 | char *colour1 = "white";
85 | char *colour2 ="blue";
86 | char okay[100]= "That's alright";
87 |
88 | initInterface(colour1, colour2); // intializing the Interface for the display
89 | // Appending the row as given order in the file of the process name
90 | for(int i = 0; i < number_of_process-1; i++){
91 | appendRow(process_array[i].processName);
92 |
93 | }
94 |
95 | // General Sorting Funciton to sort it according to there entry time
96 | sort(array, number_of_process-1);
97 | int totalTime = 0;
98 | for(int i=0 ; i< number_of_process-1; i++){
99 | totalTime = totalTime + array[i].serviceTime;
100 | array[i].remaningTime = array[i].serviceTime;
101 |
102 | }
103 |
104 |
105 |
106 | int time = array[0].entryTime; // Time Begins from 1 secs otherwise there are chances for the overlap
107 | char* caption = "Process";
108 | appendBlank(array[0].index,array[0].entryTime);
109 | array[0].state =READY;
110 | // Each process
111 | // Printing the details for the first Process
112 | int counter = 0;
113 | int i;
114 | printf("%s entered the system in %d seconds", array[0].processName, array[0].entryTime);
115 | // loop Begins to execute the each process
116 | while(totalTime> 0){
117 | // Checking for intial time for the entry of the first process
118 | if(array[counter].state != READY){
119 | appendBlank(array[counter].index,array[counter].entryTime);
120 | }
121 |
122 | i = counter;
123 |
124 | array[i].state = RUNNING;
125 | for (int j=0; j < array[i].serviceTime; j++){
126 | // Checking for any new process time
127 | if(array[i].state == RUNNING){
128 | appendBar(array[i].index,1, colour2, array[i].processName, 0);
129 | }
130 | // Checking for the next process, to update the status
131 | for(int k = i+1; k < number_of_process-1; k++){
132 | // Checking the entry time for the rest left process
133 |
134 | if(array[k].entryTime == time){
135 |
136 | printf("%s entered the system in %d seconds", array[k].processName, array[k].entryTime);
137 | //printf("Process entry Time: %d", array[k].entryTime);
138 | // Appending the blank till the EntryTime
139 | appendBlank(array[k].index,time); // Here index refers th
140 | // Updating the status of the Process with the READY STATUS
141 | array[k].state = READY;
142 |
143 | }
144 | if (array[k].state == READY){
145 | // If the left process is in the READY status then another dotted bar should be displayed on the display according to the row
146 | appendBar(array[k].index,1, colour2, array[k].processName, 1);
147 | // Adding the waiting time for that particular process
148 | array[k].waitingTime++;
149 |
150 | }
151 |
152 | }
153 | // Time counter
154 | time++;
155 | sleep(1);
156 |
157 |
158 | }
159 |
160 |
161 |
162 | // Updating the finished status for the process by EXIT enum
163 | array[i].state = EXIT;
164 | // Calculating the total time for process
165 | process_array[i].turnAroundTime = process_array[i].waitingTime + process_array[i].serviceTime;
166 | // Printing out all the end of the process with the valid details
167 | printf("%s Completed. TurnAroundTime: %d Waiting Time: %d", process_array[i].processName, process_array[i].turnAroundTime, process_array[i].waitingTime);
168 | totalTime = totalTime - array[i].serviceTime;
169 | counter ++;
170 |
171 | }
172 | waitExit();
173 |
174 |
175 | }
176 |
177 |
178 | int process_the_file(int infile){
179 | int i, file_pointer_start, end_point, read_bytes, file_pointer_end; ;
180 | char *line_buf = NULL;
181 | size_t line_buf_size = 0;
182 | int line_count = 0;
183 | ssize_t line_size;
184 |
185 |
186 | char temp[1024];
187 | int number_of_lines =0 ; // Setting default number of line read if there is no input for -n
188 | end_point = lseek(infile, 0, SEEK_END);
189 |
190 | //file_pointer_start = lseek(infile, 0 , SEEK_END);
191 |
192 |
193 |
194 | int count =0; // Dummy value to count the shift
195 | int new_process =0; // Counting the new_process
196 | i =1; // starting with the zero
197 | file_pointer_start=lseek(infile, 0 , SEEK_SET); // Initial pointer should be at zero
198 | //loop till the end of the file
199 | while(end_point - i >= 0){
200 |
201 | file_pointer_end = lseek(infile, (long)i , SEEK_SET);
202 | // reading each character from the file
203 | read_bytes = read(infile, &temp, 1);
204 | // Checking for the space
205 | if(*temp == ' '){
206 | // storing the data
207 | storing_the_data_in_struct(infile, file_pointer_start, file_pointer_end, new_process, count);
208 | //storing the last " " pointer in the file_pointer_start to read next time
209 | file_pointer_start = file_pointer_end;
210 | count++;
211 |
212 | }
213 | // getting the element from the temp using the pointer "\n"
214 | if(*temp == '\n'){
215 | // printf("%c", *temp);
216 | // storing the data
217 | storing_the_data_in_struct(infile,file_pointer_start, file_pointer_end, new_process, count);
218 | //storing the last \n pointer in the file_pointer_start to read next time
219 | file_pointer_start = file_pointer_end;
220 | new_process++;
221 | // count 0 for the new process
222 | count = 0;
223 | //printf("%s", temp);
224 | }
225 |
226 | i++ ;
227 | } // The last data before the end of the file because there is no \n hence need to hard code for it
228 | count = 2;
229 | storing_the_data_in_struct(infile,file_pointer_start, file_pointer_end, new_process, count);
230 | file_pointer_start = file_pointer_end;
231 |
232 |
233 | // printf("%d", new_process);
234 | return new_process;
235 |
236 | }
237 | int storing_the_data_in_struct(int infile, int file_pointer, int end_point, int process, int count){
238 | char temp[12];
239 | int number, k;
240 | int shift_value = 1024; // by default 1024 is good choice to take value at a time
241 | char c = '\0';
242 | // Start reading the file from the last break dude to " " or \n
243 | lseek(infile, file_pointer , SEEK_SET);
244 | k = end_point- file_pointer;
245 |
246 | number = read(infile, &temp, k); // reading 1024 bytes or minimum
247 | // printf("%d", process);
248 |
249 | // string termiantion identification
250 | temp[end_point-file_pointer] = '\0';
251 | // If the count is zero hence it is before the first space i.e. processName
252 | if (count == 0){
253 | strcpy(process_array[process].processName, temp);
254 | process_array[process].index = process;
255 | // printf("%s ", process_array[process].processName);
256 |
257 |
258 | }
259 | // If the count is one hence it is before the second space i.e. process Entry Time
260 | else if(count == 1){
261 | // strcpy(process_array[process].entryTime, temp);
262 | process_array[process].entryTime = atoi(temp);
263 | //printf("%d ", process_array[process].entryTime);
264 | }
265 | // If the count is two hence it is before the \n i.e. process service Time
266 | else if(count == 2){
267 | // strcpy(process_array[process].serviceTime, temp);
268 | process_array[process].serviceTime = atoi(temp);
269 | // printf("%d\n", process_array[process].serviceTime);
270 | }
271 | // Just random thing
272 | else{
273 | printf("READING FILE DOSEN'T WORK");
274 | }
275 | //write(1, &temp, number);
276 | // Putting the last thing
277 | // reset the lseek to read further details
278 | lseek(infile, end_point , SEEK_SET);
279 |
280 |
281 | }
282 |
283 |
284 | int sort(proc_data_t a[], int counter){
285 | int i,j;
286 | int n= counter;
287 |
288 |
289 | for (int i = 0; i < n; i++) //Loop for ascending ordering
290 | {
291 | for (int j = 0; j < n; j++) //Loop for comparing other values
292 | {
293 | if (a[j].entryTime > a[i].entryTime) //Comparing other array elements
294 | {
295 | proc_data_t tmp = a[i]; //Using temporary variable for storing last value
296 | a[i] = a[j]; //replacing value
297 | a[j] = tmp; //storing last value
298 | }
299 | }
300 | }
301 | }
302 |
--------------------------------------------------------------------------------
/preempt-28963555:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shouryaraj/Process-scheduling-simulator/35aca55a32e7ea5f8c2c2486d7e199f461475478/preempt-28963555
--------------------------------------------------------------------------------
/preempt-28963555.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #define MAX 11
14 | #include "process-visualiser.h"
15 |
16 | //#include "create-data.h"
17 |
18 |
19 | typedef enum
20 | {
21 | BLANK, READY, RUNNING, EXIT, DEADEND // DEADEND AND BLANK for more proper
22 | } process_state_t;
23 |
24 | typedef struct {
25 | char processName[11];
26 | int entryTime;
27 | int serviceTime;
28 | int remaningTime;
29 | int turnAroundTime;
30 | int waitingTime;
31 | int index; // stores the proper index according to the given file
32 | int sort_index;
33 |
34 | process_state_t state;
35 |
36 | } proc_data_t;
37 | int sort(proc_data_t a[], int counter);
38 | int process_the_file(int infile);
39 | int storing_the_data_in_struct(int infile, int file_pointer, int end_point, int process, int count);
40 | int roundRobin(int number_of_process, proc_data_t array[]);
41 | proc_data_t process_array[10];
42 |
43 | int fcfs(int number_of_process, proc_data_t array[]);
44 |
45 | int main(int argc, char *argv[]){
46 | int infile;
47 | char *fileread_error = "Error in opening the file.\n";
48 |
49 | if(argc == 1){
50 | if ((infile = open("process-data.txt", O_RDONLY)) < 0 ){
51 | write(1, fileread_error, strlen(fileread_error));
52 | close(infile);
53 | exit(2);
54 | }
55 | }
56 | else if(argc == 2){
57 | if ((infile = open(argv[1], O_RDONLY)) < 0 ){
58 | write(1, fileread_error, strlen(fileread_error));
59 | close(infile);
60 | exit(2);
61 | }
62 |
63 | }
64 | else{
65 | printf("Too many argumnet");
66 |
67 | }
68 |
69 | int number_of_process;
70 | number_of_process = process_the_file(infile); // Number of the process is getting return one extra
71 | //fcfs(number_of_process, process_array);
72 | roundRobin(number_of_process, process_array);
73 | close(infile);
74 | exit(0);
75 |
76 |
77 |
78 | }
79 | // Queue function implementation
80 |
81 | proc_data_t queue[MAX];
82 | int front = 0;
83 | int rear = -1;
84 | int itemCount = 0;
85 | // top value in the queue
86 | proc_data_t peek() {
87 | return queue[front];
88 | }
89 | // checking for the empty
90 | bool isEmpty() {
91 | return itemCount == 0;
92 | }
93 | // checking for the full of the queue
94 | bool isFull() {
95 | return itemCount == MAX;
96 | }
97 | // checking the soze of the queue
98 | int size() {
99 | return itemCount;
100 | }
101 | // pushing the value in the queue
102 | void push(proc_data_t data) {
103 |
104 | if(!isFull()) {
105 |
106 | if(rear == MAX-1) {
107 | rear = -1;
108 | }
109 |
110 | queue[++rear] = data;
111 | itemCount++;
112 | }
113 | }
114 | // removing the last value from the queue
115 | proc_data_t pop() {
116 | proc_data_t data = queue[front++];
117 |
118 | if(front == MAX) {
119 | front = 0;
120 | }
121 |
122 | itemCount--;
123 | return data;
124 | }
125 |
126 | // Round Robin Implementaion
127 |
128 | int roundRobin(int number_of_process, proc_data_t array[]){
129 |
130 | if (sizeof(proc_data_t) == 0)
131 | {
132 | return 0;
133 | }
134 | char *colour1 = "white";
135 | char *colour2 ="blue";
136 | char okay[100]= "That's alright";
137 | int totalTime = 0;
138 | proc_data_t current_process;
139 | // printf("%s", okay);
140 |
141 | initInterface(colour1, colour2); // intializing the Interface for the display
142 | // Appending the row as given order in the file of the process name
143 | for(int i = 0; i < number_of_process-1; i++){
144 | appendRow(process_array[i].processName);
145 |
146 | }
147 |
148 | // General Sorting Funciton to sort it according to there entry time
149 | sort(array, number_of_process-1);
150 | // calculating the totaltime and storing the remaining time in the process
151 | for(int i=0 ; i< number_of_process-1; i++){
152 | totalTime = totalTime + array[i].serviceTime;
153 | array[i].remaningTime = array[i].serviceTime;
154 | array[i].state = BLANK;
155 | array[i].sort_index = i;
156 | //array[i].finishTime = 0;
157 |
158 | }
159 | // intial process should be in ready state and printing for the arrival
160 | array[0].state = READY;
161 | printf(" %s entered the system at %d",array[0].processName, array[0].entryTime);
162 |
163 | // first item in the queue state
164 | push(array[0]);
165 | // updated one
166 | appendBlank(array[0].index,array[0].entryTime);
167 | // time starts at zero
168 | // updated one
169 | int time = array[0].entryTime;
170 | // time_bar for the display
171 | int quantum = 2;
172 | int count = 0;
173 | while(totalTime != 0){
174 | // Checking for the size of the queue and for the newly entered for the quantum count
175 | if(size() > 0 && count == 0){
176 | current_process = pop();
177 | current_process.state = RUNNING;
178 | if (count == 0){
179 | printf(" %s is in running state (for the given quantun)",current_process.processName);
180 | }
181 | }
182 | else{
183 | current_process.state = DEADEND;
184 |
185 | }
186 |
187 |
188 | // printf(" %d", totalTime);
189 | // printf("total Time: %d", totalTime);
190 | // Putting the current process into the Running state
191 | if (current_process.remaningTime == 1){
192 | // totalTime deduction from the current Time
193 | totalTime = totalTime - current_process.remaningTime;
194 | // time_bar = current_process.remaningTime;
195 | appendBar(current_process.index,current_process.remaningTime, colour2, current_process.processName, 0);
196 | current_process.remaningTime = 0;
197 | current_process.turnAroundTime = array[current_process.sort_index].waitingTime + current_process.serviceTime;
198 |
199 | // updating the state of the process into the EXIT status
200 | current_process.state = EXIT;
201 | // printf("process_EXIT: %s Process State: %d", current_process.processName,current_process.state);
202 | //current_process.finishTime = time;
203 | //printf("waitingTime in the exit state: %d", array[current_process.sort_index].waitingTime);
204 | printf("Process Name: %s Completed. Turnaround time: %d seconds Total wait time: %d seconds ", current_process.processName, current_process.turnAroundTime, array[current_process.sort_index].waitingTime);
205 | array[current_process.sort_index] = current_process;
206 |
207 | // making the quatum count equals to zero
208 | count = 0;
209 |
210 | // slice = true;
211 |
212 | }
213 | // Running status for the process
214 | else if(current_process.remaningTime > 1){
215 | appendBar(current_process.index, 1, colour2, current_process.processName, 0);
216 | current_process.state = RUNNING;
217 | current_process.remaningTime = current_process.remaningTime - 1;
218 | // printf("Process Name: %s in the runnnig state", current_process.processName);
219 | // total time deduction by the 1 secs
220 | totalTime = totalTime - 1;
221 | //time_bar = 1;
222 | count++;
223 | array[current_process.sort_index] = current_process;
224 |
225 |
226 | }
227 |
228 | // Checking for the next process, to update the status
229 | for(int k = 0; k < number_of_process-1; k++){
230 | // Checking the entry time for the rest left process
231 | if(array[k].entryTime == time && array[k].state == BLANK){
232 | printf("%s entered the system in %d seconds", array[k].processName, array[k].entryTime);
233 | // Appending the blank till the EntryTime
234 | appendBlank(array[k].index,time); // Here index refers th
235 | // Updating the status of the Proacess with the READY STATUS
236 | array[k].state = READY;
237 | // if next queue is nothing so next one should be first entry one
238 |
239 | push(array[k]);
240 | }
241 |
242 |
243 | if (array[k].state == READY && current_process.state != DEADEND){
244 | // If the left process is in the READY status then another dotted bar should be displayed on the display according to the row
245 | appendBar(array[k].index,1, colour2, array[k].processName, 1);
246 | // Adding the waiting time for that particular process
247 |
248 |
249 |
250 | }
251 |
252 |
253 | }
254 | // printf("size(): %d", size());
255 | // Updating the waiting time in the for queued item by one
256 | for(int l = front; l < size()+front; l++){
257 | // if it is in the system then add in the queue only
258 |
259 | queue[l].waitingTime++;
260 | // update it in as well as in the array
261 | array[queue[l].sort_index].waitingTime++;
262 | // printf("processName: %s waitingTime: %d", array[queue[l].sort_index].processName, array[queue[l].sort_index].waitingTime);
263 |
264 | }
265 |
266 |
267 | // checking for the running state and time quatum to select another process
268 | if (current_process.state == RUNNING && count == quantum){
269 | //printf("ready state to check the queue push process: %s Process State: %d", current_process.processName,current_process.state);
270 | // putting back into the READY state
271 | current_process.state = READY;
272 |
273 | // updating the array with the current_process changes
274 | array[current_process.sort_index] = current_process;
275 | // pushing back into the queue
276 | push(current_process);
277 | // array[current_process.sort_index].waitingTime++;
278 | // quantum initialzing becomes zero
279 | count = 0;
280 | }
281 |
282 | // time counter increases
283 | time ++;
284 | // sleep for a second
285 | sleep(1);
286 |
287 | }
288 |
289 | // display feature to wait
290 | waitExit();
291 |
292 |
293 | }
294 | int process_the_file(int infile){
295 | int i, file_pointer_start, end_point, read_bytes, file_pointer_end; ;
296 | char *fileread_error = "Error in opening the file.\n";
297 | char *line_buf = NULL;
298 | size_t line_buf_size = 0;
299 | int line_count = 0;
300 | ssize_t line_size;
301 |
302 |
303 | char temp[1024];
304 | int number_of_lines =0 ; // Setting default number of line read if there is no input for -n
305 | end_point = lseek(infile, 0, SEEK_END);
306 |
307 | //file_pointer_start = lseek(infile, 0 , SEEK_END);
308 |
309 |
310 |
311 | int count =0; // Dummy value to count the shift
312 | int new_process =0; // Counting the new_process
313 | i =1; // starting with the zero
314 | file_pointer_start=lseek(infile, 0 , SEEK_SET); // Initial pointer should be at zero
315 | //loop till the end of the file
316 | while(end_point - i >= 0){
317 |
318 | file_pointer_end = lseek(infile, (long)i , SEEK_SET);
319 | // reading each character from the file
320 | read_bytes = read(infile, &temp, 1);
321 | // Checking for the space
322 | if(*temp == ' '){
323 | // storing the data
324 | storing_the_data_in_struct(infile, file_pointer_start, file_pointer_end, new_process, count);
325 | //storing the last " " pointer in the file_pointer_start to read next time
326 | file_pointer_start = file_pointer_end;
327 | count++;
328 |
329 | }
330 | // getting the element from the temp using the pointer "\n"
331 | if(*temp == '\n'){
332 | // printf("%c", *temp);
333 | // storing the data
334 | storing_the_data_in_struct(infile,file_pointer_start, file_pointer_end, new_process, count);
335 | //storing the last \n pointer in the file_pointer_start to read next time
336 | file_pointer_start = file_pointer_end;
337 | new_process++;
338 | // count 0 for the new process
339 | count = 0;
340 | //printf("%s", temp);
341 | }
342 |
343 | i++ ;
344 | } // The last data before the end of the file because there is no \n hence need to hard code for it
345 | count = 2;
346 | storing_the_data_in_struct(infile,file_pointer_start, file_pointer_end, new_process, count);
347 | file_pointer_start = file_pointer_end;
348 |
349 |
350 | // printf("%d", new_process);
351 | return new_process;
352 |
353 | }
354 | int storing_the_data_in_struct(int infile, int file_pointer, int end_point, int process, int count){
355 | char temp[12];
356 | int number, k;
357 | int shift_value = 1024; // by default 1024 is good choice to take value at a time
358 | char c = '\0';
359 | // Start reading the file from the last break dude to " " or \n
360 | lseek(infile, file_pointer , SEEK_SET);
361 | k = end_point- file_pointer;
362 |
363 | number = read(infile, &temp, k); // reading 1024 bytes or minimum
364 | // printf("%d", process);
365 |
366 | // string termiantion identification
367 | temp[end_point-file_pointer] = '\0';
368 | // If the count is zero hence it is before the first space i.e. processName
369 | if (count == 0){
370 | strcpy(process_array[process].processName, temp);
371 | process_array[process].index = process;
372 | // printf("%s ", process_array[process].processName);
373 |
374 |
375 | }
376 | // If the count is one hence it is before the second space i.e. process Entry Time
377 | else if(count == 1){
378 | // strcpy(process_array[process].entryTime, temp);
379 | process_array[process].entryTime = atoi(temp);
380 | //printf("%d ", process_array[process].entryTime);
381 | }
382 | // If the count is two hence it is before the \n i.e. process service Time
383 | else if(count == 2){
384 | // strcpy(process_array[process].serviceTime, temp);
385 | process_array[process].serviceTime = atoi(temp);
386 | // printf("%d\n", process_array[process].serviceTime);
387 | }
388 | // Just random thing
389 | else{
390 | printf("READING FILE DOSEN'T WORK");
391 | }
392 | //write(1, &temp, number);
393 | // Putting the last thing
394 | // reset the lseek to read further details
395 | lseek(infile, end_point , SEEK_SET);
396 |
397 |
398 | }
399 |
400 |
401 | int sort(proc_data_t a[], int counter){
402 | int i,j;
403 | int n= counter;
404 |
405 |
406 | for (int i = 0; i < n; i++) //Loop for ascending ordering
407 | {
408 | for (int j = 0; j < n; j++) //Loop for comparing other values
409 | {
410 | if (a[j].entryTime > a[i].entryTime) //Comparing other array elements
411 | {
412 | proc_data_t tmp = a[i]; //Using temporary variable for storing last value
413 | a[i] = a[j]; //replacing value
414 | a[j] = tmp; //storing last value
415 | }
416 | }
417 | }
418 | }
419 |
420 |
421 |
--------------------------------------------------------------------------------
/process-data.txt:
--------------------------------------------------------------------------------
1 | p1 0 3
2 | p2 2 6
3 | p3 4 4
4 | p4 6 5
5 | p5 8 2
6 |
--------------------------------------------------------------------------------
/process-visualiser.c:
--------------------------------------------------------------------------------
1 | /*
2 | PROCESS VISUALISER API FOR FIT2100 ASSIGNMENT 2 (Scheduling simulator)
3 | Written by Daniel Kos, Sep 2019.
4 |
5 | Refer to process-visualiser.h for instructions.
6 |
7 | You are not required to understand the contents of this file to complete
8 | the assignment.
9 | */
10 |
11 | #include
12 |
13 | void initInterface(const char* backgroundColor, const char* foregroundColor) {
14 |
15 | //prevent user exiting until waitExit() is called.
16 | printf(">\n");
17 | printf(" \n");
18 | printf("\n", backgroundColor);
19 | printf("\n", foregroundColor);
20 |
21 | printf(
22 | " \n" //provide a space for mouse-over caption to be displayed.
24 | " \n"
26 | "}>\n"
27 | );
28 |
29 | //print a visual time scale along the top of the chart...
30 | printf("");
32 | for(int time=1; time<=90; time++)
33 | printf("", time);
34 | printf("}>"); //label the axis.
35 | printf("}>}>\n");
36 |
37 | printf("\n"); //show the chart area ready for rows and bars.
38 | printf("", processName);
48 | printf("}>}>\n");
49 |
50 | return numRows++; //return the row index and increment for next time.
51 | }
52 |
53 |
54 | void appendBar(int rowIndex, int length, const char* color, const char* caption, int dotted) {
55 |
56 | printf(", ", caption);
58 | if(dotted) printf("borderStyle={dotted} ");
59 | else printf("backgroundColor={%s} ", color);
60 | printf("height=30 width=%d {}", length*30);
61 | printf(">>\n");
62 | }
63 |
64 | void appendBlank(int rowIndex, int length) {
65 |
66 | printf(">\n");
69 |
70 | }
71 |
72 |
73 |
74 |
75 | void waitExit() {
76 | //This function places an exit button on the screen and allows the user to exit the program.
77 | //It will not return until the user has clicked the exit (or window X) button.
78 | //After return, the program is free to handle the exit condition (e.g. by
79 | //exiting the program.
80 |
81 |
82 |
83 | printf(">\n");
84 | printf("\n");
85 |
86 | getchar(); //block until "X" input is received on stdin.
87 |
88 | //prevent the user repeating the operation
89 | printf(">\n");
90 | printf("\n");
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/process-visualiser.h:
--------------------------------------------------------------------------------
1 | /*
2 | PROCESS VISUALISER API FOR FIT2100 ASSIGNMENT 2 (Scheduling simulator)
3 | Written by Daniel Kos, Sep 2019.
4 |
5 |
6 | This file provides access to 5 functions used to plot visual information
7 | on the screen for this assignment.
8 |
9 | * When running your program, place 'iol --' in front of the command, to
10 | run your program in the ioL markup console environment.
11 |
12 |
13 | TO INCLUDE THESE FUNCTIONS IN YOUR PROGRAM:
14 | * Place this file and process-visualiser.c in the same directory as your assignment.
15 | * Place the following line at the top of any source file that requires these
16 | functions: (This includes the function header information in your program)
17 | #include "process-visualiser.h
18 | * When COMPILING your program: add ' process-visualiser.c' to the end of the
19 | gcc command used to compile your program. (This links the function implementations
20 | with your compiled program.)
21 | e.g. gcc your-program.c -o your-program process-visualiser.c
22 |
23 |
24 | DO NOT RENAME THESE FILES IN YOUR SUBMISSION, OR COPY THE FUNCTIONS INTO
25 | YOU CODE DIRECTLY.
26 |
27 | You may modify the functions in process-visualiser.c if you wish, however
28 | you are not required to do so.
29 |
30 | */
31 |
32 | #ifndef PROCESS_VISUALISER_H_ //guard against multiple #includes.
33 | #define PROCESS_VISUALISER_H_
34 |
35 | void initInterface(const char* backgroundColor, const char* foregroundColor);
36 | /*
37 | This function must be called first (prior to producing any output) to set up the user interface
38 |
39 | RETURN VALUE: none.
40 |
41 | ARGUMENTS:
42 | * backgroundColor: a string defining the background color for the window.
43 | * foregroundColor: a string defining the foreground color for the window.
44 |
45 | NOTE: the following color values are accepted:
46 | "black", "silver", "gray", "white", "maroon", "red", "purple", "fuchsia", "green",
47 | "lime", "olive", "yellow", "navy", "blue", "teal", "aqua".
48 | */
49 |
50 |
51 |
52 | int appendRow(const char* processName);
53 | /*
54 | This function adds a new process row to the chart displayed on the screen
55 |
56 | RETURN VALUE: the row index of the new row in the chart. Use this value with
57 | the appendBar and appendBlank functions when you want to specify which process
58 | to append a bar or a blank space to.
59 |
60 | ARGUMENTS:
61 | * processName: a string used to label the row in the chart as displayed on screen.
62 | (This should be the name of the process being added to the system.)
63 | */
64 |
65 |
66 |
67 | void appendBar(int rowIndex, int length, const char* color, const char* caption, int dotted);
68 | /*
69 | This function draws a bar segment to the end of the specified row.
70 | This is useful to represent that the process is in a certain state for a certain
71 | length of time.
72 |
73 | RETURN VALUE: none
74 |
75 | ARGUMENTS:
76 | * rowIndex: the row index of the row where you want to append the bar segment.
77 | * length: the length of the bar (measured in seconds) -- represents how much time
78 | the process is in a certain state
79 | * color: a string defining the color to use for the bar segment (see below).
80 | * caption: a string to be displayed when the user moves the mouse over the bar.
81 | * dotted: Either 1 or 0. If 1, a dotted bar will be drawn (process in ready state/waiting).
82 | If 0, a solid bar will be drawn (process is running).
83 |
84 | NOTE: the following color values are accepted:
85 | "black", "silver", "gray", "white", "maroon", "red", "purple", "fuchsia", "green",
86 | "lime", "olive", "yellow", "navy", "blue", "teal", "aqua".
87 | */
88 |
89 |
90 |
91 | void appendBlank(int rowIndex, int length);
92 | /*
93 | This function adds a blank space to the end of the specified row.
94 | This is useful to represent that a process has not arrived in the system yet.
95 | The next bar to be added to the row will be added after the end of the blank
96 | space.
97 |
98 | RETURN VALUE: none
99 |
100 | ARGUMENTS:
101 | * rowIndex: the row index of the row where you want to append the bar segment.
102 | * length: the length of the bar (measured in seconds).
103 | */
104 |
105 |
106 |
107 | void waitExit();
108 | /*
109 | This function allows the user to close the window once all the output has been printed.
110 | It will not return *until* the user clicks the 'close' or 'exit' button,
111 | so it allows you to keep the window on the screen until the user is ready to exit.
112 |
113 | RETURN VALUE: none (function returns when user has clicked the close button)
114 |
115 | ARGUMENTS: none.
116 |
117 | NOTE: This function does not close the window. The window will close when the program exits.
118 | */
119 |
120 | //end of header file.
121 | #endif
122 |
--------------------------------------------------------------------------------
/resource/scheduler_pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shouryaraj/Process-scheduling-simulator/35aca55a32e7ea5f8c2c2486d7e199f461475478/resource/scheduler_pic.png
--------------------------------------------------------------------------------
/user_manual.txt:
--------------------------------------------------------------------------------
1 | FCFS and ROUND_ROBIN user commands
2 | Name
3 | non-preemtive-28963555 - graphic display the ROUND_ROBIN scheduler work
4 | preemtive-28963555 -graphic display the FCFS scheduler work
5 |
6 | SYNOPSIS
7 | ./non-preemtive-28963555 [fileName]
8 | or
9 | ./non-preemtive-28963555
10 | &
11 | ./preemtive-28963555 [fileName]
12 | or
13 | ./preemtive-28963555
14 | Description
15 | Graphic display of the given process in the file accordinf to the choosen scheduler
16 |
17 | commands:
18 | ./non-preemtive-28963555 [fileName], it reads the given fileName and display the graphic of the process execution using the
19 | ROUND_ROBIN scheduler
20 | Limitaion:
21 | filename should be there is same directory
22 |
23 | ./non-preemtive-28963555, it reads by default fileName "process-data.txt" and display the graphic of the process execution using the
24 | ROUND_ROBIN scheduler
25 |
26 | ./preemtive-28963555 [fileName], it reads the given fileName and display the graphic of the process execution using the
27 | FCFS scheduler
28 | Limitaion:
29 | filename should be there is same directory
30 |
31 | ./preemtive-28963555, it reads by default fileName "process-data.txt" and display the graphic of the process execution using the
32 | FCFS scheduler
33 |
34 | Overall Limitation:
35 | filename should be there and Process time should be a natural number, process name should not more than 10 characters.
36 |
37 | Author:
38 | Written by Shourya Raj
--------------------------------------------------------------------------------