GoodDeeds
GoodDeeds

Reputation: 8527

Usage of scheduling policy flags SCHED_BATCH or SCHED_IDLE gives error

I am trying to use sched_setscheduler() to set the scheduling policy of a given process. As per its man page, the available flags are SCHED_FIFO,SCHED_RR,SCHED_OTHER,SCHED_BATCH,SCHED_IDLE.

Except for SCHED_BATCH and SCHED_IDLE, I am able to use all the flags and compile my program successfully. However, using, say, SCHED_BATCH, I get

error: ‘SCHED_BATCH’ undeclared (first use in this function)
sched_setscheduler(getpid(),SCHED_BATCH,&param);

A sample code to illustrate my problem is:

#include<stdio.h>
#include<unistd.h>
#include<sched.h>
#include<time.h>
#include<stdlib.h>
#include<sys/types.h>
int main()
{
    struct sched_param p;
    p.sched_priority=0;
    sched_setscheduler(getpid(),SCHED_BATCH,&p);
    return 0;
}

As mentioned in the man page, I have created an object of typr sched_param, set its appropriate sched_priority value, and passed it to the function.

My linux kernel version is 4.4.40 and I am using Ubuntu 14.04.5 LTS. My gcc version is 6.2.0.

How do I resolve this?

Upvotes: 1

Views: 2289

Answers (1)

P.P
P.P

Reputation: 121417

SCHED_BATCH and SCHED_IDLE are Linux specific and are not part of POSIX standard.

Glibc doesn't expose them unless you define _GNU_SOURCE. So, do:

#define _GNU_SOURCE

before including headers.

Upvotes: 4

Related Questions