* Scheduling parameters of a process and its main thread
@ 2006-07-13 6:29 Olivier Croquette
0 siblings, 0 replies; only message in thread
From: Olivier Croquette @ 2006-07-13 6:29 UTC (permalink / raw)
To: LKML
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-07-13 6:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-13 6:29 Scheduling parameters of a process and its main thread Olivier Croquette
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.