Skip to content

Instantly share code, notes, and snippets.

@mayli
Created July 19, 2015 21:54
Show Gist options
  • Save mayli/9e03652c47117390cf78 to your computer and use it in GitHub Desktop.
Save mayli/9e03652c47117390cf78 to your computer and use it in GitHub Desktop.
play with SCHED_RR
#include <stdio.h>
#include <errno.h>
#include <sched.h>
#include <sys/types.h>
#include <unistd.h>
void print_sched(){
printf("PID=%d, SCHED=%d\n", getpid(), sched_getscheduler(getpid()));
}
int set_sched(int policy, int priority){
int ret;
struct sched_param param;
param.sched_priority = priority;
ret = sched_setscheduler(getpid(), policy, &param);
if (ret)
perror("sched_setscheduler");
return ret;
}
int main(){
print_sched();
printf("sched_setscheduler()->%d\n", set_sched(SCHED_RR, sched_get_priority_max(SCHED_RR)));
print_sched();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment