Scheduler operations, see each function below.
At the time of writing, only round robin scheduling is available. It has three priorities, 0 for max, 1 for normal (default) and 2 for low. Operations for other scheduling policies or priorities will return error.
sched_get_priority_max
Get the maximum priority for a given scheduling policy.
Syntax
#include <sched.h>
int sched_get_priority_max (int policy);
Parameters
-
policy
The policy to get the maximum for. Currently, the only available policy is
SCHED_RR
for round-robin scheduling.
Return Value
The return value is the maximum priority if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
Unsupported scheduling policy (not
SCHED_RR
).
Remarks
None
sched_get_priority_min
Get the minimum priority for a given scheduling policy.
Syntax
#include <sched.h>
int sched_get_priority_min (int policy);
Parameters
-
policy
The policy to get the minimum for. Currently, the only available policy is
SCHED_RR
for round-robin scheduling.
Return Value
The return value is the minimum priority if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
Unsupported scheduling policy (not
SCHED_RR
).
Remarks
None
sched_getparam
Get the parameters for the current scheduling policy for the given PID.
Syntax
#include <sched.h>
int sched_getparam (pid_t pid, struct sched_param *params);
Parameters
-
pid
The process ID to retrieve the parameters for.
-
params
A structure to be filled in. Contains the
sched_priority
member.
Return Value
The return value is zero if successful, with the parameters written to the supplied structure. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
The
params
argument is invalid. -
EACCES
The PID is not valid or the caller does not have access to it.
Remarks
Programs are only allowed to request the policy for itself.
sched_getscheduler
Get the current scheduling policy for the given PID.
Syntax
#include <sched.h>
int sched_getscheduler (pid_t pid);
Parameters
-
pid
The process ID to retrieve the policy for.
Return Value
The return value is the current policy if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EACCES
The PID is not valid or the caller does not have access to it.
Remarks
Programs are only allowed to request the policy for itself.
sched_rr_get_interval
Get the current scheduling interval for the given PID.
Syntax
#include <sched.h>
int sched_rr_get_interval (pid_t pid, struct timespec *time);
Parameters
-
pid
The process ID to retrieve the time interval for.
-
time
The time structure that will receive the time interval data.
Return Value
The return value is zero if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
The
time
argument is invalid. -
EACCES
The PID is not valid or the caller does not have access to it.
Remarks
None
sched_setparam
Set the scheduling parameters for the given PID.
Syntax
#include <sched.h>
int sched_setparam (pid_t pid, const struct sched_param *params);
Parameters
-
pid
The process ID to set the policy for.
-
params
The structure that specifies the policy parameter data.
Return Value
The return value is zero if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
The
params
argument is invalid. -
EACCES
The PID is not valid or the caller does not have access to it.
Remarks
This function will implicitly call yield to reschedule.
sched_setscheduler
Set the scheduling parameters and policy for the given PID.
Syntax
#include <sched.h>
int sched_setscheduler (pid_t pid, int policy, const struct sched_param *params);
Parameters
-
pid
The process ID to set the policy for.
-
policy
The scheduling policy to use.
-
params
The structure that specifies the policy parameter data.
Return Value
The return value is zero if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
-
EINVAL
The
policy
orparams
argument is invalid. -
EACCES
The PID is not valid or the caller does not have access to it.
Remarks
This function will implicitly call yield to reschedule.
sched_yield
Yield the CPU.
Syntax
#include <sched.h>
int sched_yield (void);
Parameters
None
Return Value
The return value is zero if successful. Otherwise, the return value is negative and errno is set:
-
ENOSYS
Operation not supported. May be returned if there was an internal system call error or the API is not available because it has been disabled.
Remarks
None