Choosing the Scheduling Policy with GNU/Linux (GNAT User’s Guide for Native Platforms)

#### 7.3.3 Choosing the Scheduling Policy with GNU/Linux ¶

When using a POSIX threads implementation, you have a choice of several scheduling policies: `SCHED_FIFO`, `SCHED_RR` and `SCHED_OTHER`.

Typically, the default is `SCHED_OTHER`, while using `SCHED_FIFO` or `SCHED_RR` requires special (e.g., root) privileges.

By default, GNAT uses the `SCHED_OTHER` policy. To specify `SCHED_FIFO`, you can use one of the following:

- `pragma Time_Slice (0.0)`
- the corresponding binder switch `-T0`
- `pragma Task_Dispatching_Policy (FIFO_Within_Priorities)`

To specify `SCHED_RR`, you should use `pragma Time_Slice` with a value greater than 0.0, or else use the corresponding `-T` binder switch.

To make sure a program is running as root, you can put something like this in a library package body in your application:

>     function geteuid return Integer;
>     pragma Import (C, geteuid, "geteuid");
>     Ignore : constant Boolean :=
>       (if geteuid = 0 then True else raise Program_Error with "must be root");

This gets the effective user id and if it’s not 0 (i.e. root), it raises Program_Error. Note that if you’re running the code in a container, this may not be sufficient as you may have sufficient privilege on the container, but not on the host machine running the container, so check that you also have sufficient privilege for running the container image.