add more spacing
[personal-kdebase.git] / workspace / ksysguard / gui / setscheduler.c
blob9087c178b8a4587624f7a88c0feed7ef026cfc7f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sched.h>
5 int main(int argc, char **argv)
7 if(argc != 4) {
8 fprintf(stderr, "Usage: %s PID SCHEDULER PRIORITY\n", argv[0]);
9 fprintf(stderr, "Sets the CPU Scheduler and priority for the given PID.\n See man sched_setscheduler for more information\n\n");
10 fprintf(stderr, "SCHEDULER is one of:\n");
11 fprintf(stderr, " 0 Other\n");
12 fprintf(stderr, " 1 FIFO\n");
13 fprintf(stderr, " 2 RoundRobin\n");
14 #ifdef SCHED_BATCH
15 fprintf(stderr, " 3 Batch\n");
16 #endif
17 exit(EXIT_FAILURE);
19 int pid = atoi(argv[1]);
20 int priorityClass = atoi(argv[2]);
21 int priority = atoi(argv[3]);
22 printf("Setting scheduler for %d to %d %d\n", pid, priorityClass, priority);
24 struct sched_param params;
25 params.sched_priority = priority;
26 int result;
27 switch(priorityClass) {
28 case 0:
29 result = sched_setscheduler( pid, SCHED_OTHER, &params);
30 break;
31 case 1:
32 result = sched_setscheduler( pid, SCHED_FIFO, &params);
33 break;
34 case 2:
35 result = sched_setscheduler( pid, SCHED_RR, &params);;
36 break;
37 #ifdef SCHED_BATCH
38 case 3:
39 result = sched_setscheduler( pid, SCHED_BATCH, &params);
40 break;
41 #endif
42 default:
43 fprintf(stderr, "Invalid Priority class\n");
44 exit(EXIT_FAILURE);
46 if(result != 0) {
47 perror("Failure setting scheduler");
50 return result;