-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.c
43 lines (33 loc) · 1.12 KB
/
process.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "process.h"
// This file will have all the process related functions
// print some info about the given process
void print_process(struct process *p)
{
printf("P%d: CPU Cycles:%d, Period:%.2f.\n", p->PID, p->cpu_cycles, p->period);
}
// create a new process from given parameters, (much like the constructor for a class)
struct process *create_process(int cpu_cycles, float period)
{
struct process *p = malloc(sizeof(struct process)); // empty container
// PID will be assigned by the Scheduler
// assign values
p->cpu_cycles = cpu_cycles;
p->period = period;
p->deadline = period;
p->release_time = 0.0;
p->priority = 10.0;
p->completions = 0;
p->actual_cycles = 0; // this value has to be randomly generated on every release of a process
p->util = p->cpu_cycles / p->period;
return p; // return
}
int actual_cycles(struct process *p)
{
// set the actual cycles --> [1, cpu_cycles]
srand(time(0));
p->actual_cycles = rand() % p->cpu_cycles + 1;
return p->actual_cycles; // return for ease of use
}