[Previous]
[Contents]
[Next]

qnx_scheduler()

change the priority and scheduling policy for a process

Synopsis:

#include <sys/sched.h>
int qnx_scheduler( pid_t proc_pid, pid_t pid,
                   int alg, int prio, 
                   int ret );

Description:

The qnx_scheduler() function changes the priority of process pid, on the node identified by proc_pid, to prio, and its scheduling policy to alg. If proc_pid and pid are 0, the calling process is used. If alg or prio is -1, the current value isn't changed.

To affect a process on another node, proc_pid should be passed as a virtual circuit to the process manager on that node.

/* Attach a vc to the process manager on node 4 */
proc_pid = qnx_vc_attach( 4, PROC_PID, 0, 0 );

The alg parameter must be one of the following:

SCHED_FIFO
A fixed priority scheduler in which the highest ready process runs until it blocks or is preempted by a higher priority process.
SCHED_RR
The same as SCHED_FIFO, except processes at the same priority level time-slice (round robin).
SCHED_OTHER
A general time sharing scheduler in which a process decays in priority if it consumes too much processor before blocking. It reverts to its default priority when it blocks. A process never decays beyond one less than its original priority.

The prio parameter must lie between 1 (lowest) and 29 (highest for superuser) or 19 (highest for non-superuser).

By default the priority and scheduling algorithm of a process are inherited or explicitly set by the process that created it. Once running, it may change them using this function.

Returns:

If the qnx_scheduler() function succeeds, the return value depends on the ret argument, as follows:

ret Value returned
Nonzero Previous scheduling policy
Zero Previous priority

On error, -1 is returned and errno is set.

Errors:

EINVAL
The priority prio or scheduling policy alg isn't a valid value.
EPERM
The calling process doesn't have sufficient privilege to set the priority.
ESRCH
The process pid doesn't exist.

Examples:

#include <stdio.h>
#include <sys/sched.h>

void main()
  {
    struct sched_param param;

    printf( "My priority is %d.\n", getprio( 0 ) );
    printf( "My scheduler is %d.\n\n", sched_getscheduler( 0 ) );

    setprio( 0, 7 );
    printf( "My priority is %d.\n", getprio( 0 ) );
    printf( "My scheduler is %d.\n\n", sched_getscheduler( 0 ) );

    param.sched_priority = 6;
    sched_setscheduler( 0, SCHED_FIFO, &param );
    printf( "My priority is %d.\n", getprio( 0 ) );
    printf( "My scheduler is %d.\n\n", sched_getscheduler( 0 ) );

    qnx_scheduler( 0, 0, -1, 5, 0 );
    printf( "My priority is %d.\n", getprio( 0 ) );
    printf( "My scheduler is %d.\n\n", sched_getscheduler( 0 ) );

    qnx_scheduler( 0, 0, SCHED_RR, -1, 1 );
    printf( "My priority is %d.\n", getprio( 0 ) );
    printf( "My scheduler is %d.\n\n", sched_getscheduler( 0 ) );
  }

produces the output:

My priority is 10.
My scheduler is 2.

My priority is 7.
My scheduler is 2.

My priority is 6.
My scheduler is 0.

My priority is 5.
My scheduler is 0.

My priority is 5.
My scheduler is 1.

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, getprio(), qnx_vc_attach(), sched_getscheduler(), sched_setparam(), sched_setscheduler(), sched_yield(), setprio(), Yield()

"Process scheduling" in the Microkernel chapter of the QNX System Architecture guide


[Previous]
[Contents]
[Next]