I have an application running on Linux using SCHED_FIFO via pthread_attr_setschedpolicy.
My understanding is that pthread_attr_setschedparam() should allow setting the thread priority on a thread attributes structure before the thread is launched and Posix requires at least 32 levels are supported.
Indeed while running:
sched_get_priority_max(SCHED_FIFO) = 99
sched_get_priority_min(SCHED_FIFO) = 1
The thread priority is set before pthread_create using:
pthread_attr_setinheritsched(&thread_attr,PTHREAD_EXPLICIT_SCHED))
pthread_attr_setschedparam(&thread_attr)
If I interrogate it
pthread_attr_t thread_attr;
struct sched_param s_param;
int res = pthread_getattr_np(channel_data_p->thread, &thread_attr);
assert(res == 0);
res = pthread_attr_getschedparam (&thread_attr, &s_param);
assert(res == 0);
log_write("thread %d, priority = %d",threadId,s_param.sched_priority);
I see the expected priority. However, I'm not clear how to display the pthreads priority using ps -o, top -H or looking in /proc or how to relate Linux values like PR and NI (if they are the right fields to watch under top -H) back to the posix priority.
I have no intention of messing with the priorities dynamically so this is more of academic interest.