examples/user/main.c
branchstable-1.5
changeset 2697 4f5ae7e0fbaa
parent 2664 14a18eae7e3b
equal deleted inserted replaced
2696:2b072c95b34c 2697:4f5ae7e0fbaa
    35 #include <sys/time.h>
    35 #include <sys/time.h>
    36 #include <sys/types.h>
    36 #include <sys/types.h>
    37 #include <unistd.h>
    37 #include <unistd.h>
    38 #include <time.h> /* clock_gettime() */
    38 #include <time.h> /* clock_gettime() */
    39 #include <sys/mman.h> /* mlockall() */
    39 #include <sys/mman.h> /* mlockall() */
       
    40 #include <sched.h> /* sched_setscheduler() */
    40 
    41 
    41 /****************************************************************************/
    42 /****************************************************************************/
    42 
    43 
    43 #include "ecrt.h"
    44 #include "ecrt.h"
    44 
    45 
   351         return -1;
   352         return -1;
   352     }
   353     }
   353 
   354 
   354     /* Set priority */
   355     /* Set priority */
   355 
   356 
   356     pid_t pid = getpid();
   357     struct sched_param param = {};
   357     if (setpriority(PRIO_PROCESS, pid, -19)) {
   358     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
   358         fprintf(stderr, "Warning: Failed to set priority: %s\n",
   359 
   359                 strerror(errno));
   360     printf("Using priority %i.", param.sched_priority);
       
   361     if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
       
   362         perror("sched_setscheduler failed");
   360     }
   363     }
   361 
   364 
   362     /* Lock memory */
   365     /* Lock memory */
   363 
   366 
   364     if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
   367     if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {