-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPF.cpp
68 lines (61 loc) · 1.59 KB
/
SPF.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "structures.h"
#include "Fonctions.h"
process* choose_SPF_Process (processList* L)
{
process* selectedprocess = NULL;
for(int i=0; i < L->process_nbr; i++ )
{
if(L->allProcess[i].process_status == READY)
{
selectedprocess = L->allProcess+i;
break;
}
}
if(selectedprocess == NULL)
return NULL;
for(int i=0; i < L->process_nbr; i++ )
{
if (L->allProcess[i].exec_time < selectedprocess->exec_time &&
L->allProcess[i].process_status == READY)
selectedprocess = L->allProcess+i;
}
return selectedprocess;
}
void start_SPF_processor (processList* L)
{
int clock = 0;
process* runningprocess = NULL;
while(!is_all_process_end (L))
{
update_all_ready_process(L , clock);
if( runningprocess != choose_SPF_Process(L))
{
if(runningprocess){
if(runningprocess->process_status==ZOMBIE){
L->context_chges_nbr++;
runningprocess = choose_SPF_Process(L);
}
}else{
L->context_chges_nbr++;
runningprocess = choose_SPF_Process(L);
}
}
if(runningprocess)
{
clock++;
runningprocess->real_exec_time ++;
runningprocess->process_status = RUNNING;
L->exec_string[strlen(L->exec_string)+1] = '\0';
L->exec_string[strlen(L->exec_string)] = runningprocess->process_name;
if(runningprocess->real_exec_time == runningprocess->exec_time )
{
runningprocess->process_status = ZOMBIE;
runningprocess->end_date = clock;
}
}
else
{
clock++;
}
}
}