Use sched_setscheduler() to set priority in user example.

This commit is contained in:
Florian Pose 2018-02-06 14:58:14 +01:00
parent 2b2c7c9613
commit 098dddb1e7
1 changed files with 7 additions and 4 deletions

View File

@ -37,6 +37,7 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> /* clock_gettime() */ #include <time.h> /* clock_gettime() */
#include <sys/mman.h> /* mlockall() */ #include <sys/mman.h> /* mlockall() */
#include <sched.h> /* sched_setscheduler() */
/****************************************************************************/ /****************************************************************************/
@ -353,10 +354,12 @@ int main(int argc, char **argv)
/* Set priority */ /* Set priority */
pid_t pid = getpid(); struct sched_param param = {};
if (setpriority(PRIO_PROCESS, pid, -19)) { param.sched_priority = sched_get_priority_max(SCHED_FIFO);
fprintf(stderr, "Warning: Failed to set priority: %s\n",
strerror(errno)); printf("Using priority %i.", param.sched_priority);
if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
perror("sched_setscheduler failed");
} }
/* Lock memory */ /* Lock memory */