public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olivier Croquette <ocroquette@free.fr>
To: LKML <linux-kernel@vger.kernel.org>
Subject: Scheduling parameters of a process and its main thread
Date: Thu, 13 Jul 2006 08:29:07 +0200	[thread overview]
Message-ID: <44B5E833.6000808@free.fr> (raw)

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,&param);
   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, &param) ) {
     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;
}

                 reply	other threads:[~2006-07-13  6:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44B5E833.6000808@free.fr \
    --to=ocroquette@free.fr \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox