• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <sched.h>
2 #include <stdio.h>
3 #include <errno.h>
4 #include <string.h>
5 #include "test.h"
6 
7 #define TEST(c) ((!c) ? 1 : (t_error(#c" failed: %s" ,strerror(errno)),0))
8 
main(int argc,char * argv[])9 int main(int argc,char *argv[])
10 {
11     struct sched_param param;
12     int maxpri,minpri;
13     int sched;
14     pid_t pid;
15 
16     sched = SCHED_FIFO;
17     pid = getpid();
18     maxpri = sched_get_priority_max(sched);
19     minpri = sched_get_priority_min(sched);
20     if(maxpri == -1 || minpri == -1)
21     {
22         perror("get maxpriority or minpriority failed");
23         return -1;
24     }
25     param.sched_priority = 23;//取值范围:minpri~maxpri
26     TEST(sched_setscheduler(pid, sched, &param));
27     TEST(!(sched_getscheduler(pid) == sched));
28     TEST(sched_getparam(pid, &param));
29 
30     return 0;
31 }
32 
33