Linux doesn't allow you to set a thread's scheduling priority directly; instead, you can set the niceness value, using the nice(2) function:
Code:
#include <unistd.h>
int nice(int inc); //returns 0 on success or -1 on error (sets errno)
Edit: In response to your email, it seems that some implementations return the actual nice value. From the manpage:
Quote:
NOTES
Note that the routine is documented in SUSv2 and POSIX 1003.1-2003 to return the new nice value,
while the Linux syscall and (g)libc (earlier than glibc 2.2.4) routines return 0 on success. The
new nice value can be found using getpriority(2). Note that an implementation in which nice returns
the new nice value can legitimately return -1. To reliably detect an error, set errno to 0 before
the call, and check its value when nice returns -1.
|
The nice values range from -19 (most foreground; highest priority) to +20 (most background; lowest priority). The initial default is usually 0.
Reducing the nice value is a privilaged instruction that requires superuser powers.
The getpriority(2) call returns the current nice value, and the nice and renice programs can be used to change niceness from the shell.
The actual scheduling priority is set depending on the nice value, recent schedular performance, and other system loads.