change the priority and scheduling policy for a process
#include <sys/sched.h> int qnx_scheduler( pid_t proc_pid, pid_t pid, int alg, int prio, int ret );
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:
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.
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.
#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, ¶m ); 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.
QNX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
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