Hi
When a process only has one thread, I would expect that sched_get* and
pthread_getschedparam return equivalent priorities.
But in the example below, it's not the case.
What I do:
- print priorities
- give RT priority to the process
- print priorities
- give RT priority to the thread
- print priorities
1. Process 3938 : policy=0 prio=0
1. Thread 1075147872 : policy=0 prio=0
2. Process 3938 : policy=1 prio=20
2. Thread 1075147872 : policy=0 prio=0
3. Process 3938 : policy=1 prio=30
3. Thread 1075147872 : policy=1 prio=30
As you can see, at the step to, the process and the thread don't have
the same parameters.
Is that normal?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pthread.h>
/* gcc schedparam.c -o schedparam -Wall -pthread */
int print_process_sched(pid_t pid) {
struct sched_param param;
int prio;
int policy;
policy = sched_getscheduler(pid);
sched_getparam(pid,¶m);
prio = param.sched_priority;
printf("Process %d : policy=%d prio=%d\n",(int)pid, policy,prio);
return 0;
}
int utilities_print_thread_sched(pthread_t id) {
struct sched_param param;
int policy;
int prio;
unsigned long int lid = id;
if ( pthread_getschedparam(id, &policy, ¶m) ) {
perror("pthread_getschedparam()"); return 1;
}
prio = param.sched_priority;
printf("Thread %ld : policy=%d prio=%d\n", (long)lid, policy,prio);
return 0;
}
int main(void ) {
struct sched_param p;
printf("1. "); print_process_sched(getpid());
printf("1. "); utilities_print_thread_sched(pthread_self());
p.sched_priority = 20;
if ( sched_setscheduler(getpid(),SCHED_FIFO,&p) ) {
perror("sched_setscheduler()");
return 1;
}
printf("2. "); print_process_sched(getpid());
printf("2. "); utilities_print_thread_sched(pthread_self());
p.sched_priority = 30;
if ( pthread_setschedparam(pthread_self(),SCHED_FIFO,&p) ) {
perror("sched_setscheduler()");
return 1;
}
printf("3. "); print_process_sched(getpid());
printf("3. "); utilities_print_thread_sched(pthread_self());
return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]