-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrr_quantum.c
58 lines (47 loc) · 1.43 KB
/
rr_quantum.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* File: rr_quantum.c
* Author: Andy Sayler
* Project: CSCI 3753 Programming Assignment 3
* Create Date: 2012/03/22
* Modify Date: 2012/03/22
* Description: Prints the RR quantum for a given system.
*/
/* Library Includes */
#include <errno.h>
#include <sched.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#define NANO 1000000000.0
int main(int argc, char* argv[]){
(void) argc;
(void) argv;
struct sched_param param;
int policy;
struct timespec tp;
double qs = 0.0;
/* Set Policy */
policy = SCHED_RR;
/* Set process to max prioty for given scheduler */
param.sched_priority = sched_get_priority_max(policy);
/* Set new scheduler policy */
fprintf(stdout, "Current Scheduling Policy: %d\n", sched_getscheduler(0));
fprintf(stdout, "Setting Scheduling Policy to: %d\n", policy);
if(sched_setscheduler(0, policy, ¶m)){
perror("Error setting scheduler policy");
exit(EXIT_FAILURE);
}
fprintf(stdout, "New Scheduling Policy: %d\n", sched_getscheduler(0));
/* Find RR Quantum */
if(sched_rr_get_interval(getpid(), &tp)){
perror("Error getting RR Quantum");
exit(EXIT_FAILURE);
}
fprintf(stdout, "tp.tv_sec = %ld\n", tp.tv_sec);
fprintf(stdout, "tp.tv_nsec = %ld\n", tp.tv_nsec);
qs = (tp.tv_nsec / NANO) + tp.tv_sec;
fprintf(stdout, "RR Quantum = %f seconds\n", qs);
return 0;
}