De forma predeterminada, los programas se ejecutan con Tiempo compartido (política de TS) en Linux. ¿Cómo ejecutar un programa con la política SCHED_RR en Linux desde la línea de comandos?
Gracias por dar información sobre el comando chrt (1). He usado el comando para ejecutar Firefox con la política RR, pero como puede ver a continuación, solo el hilo principal de Firefox se ejecuta con la política RR. ¿Podría decirme cómo ejecutar todos los otros hilos de Firefox también con la política RR.
$ ps -Lo pid,tid,class 2051
  PID   TID CLS
 2051  2051 RR
 2051  2055 TS
 2051  2056 TS
 2051  2057 TS
 2051  2058 TS
 2051  2059 TS
 2051  2060 TS
 2051  2061 TS
 2051  2063 TS
 2051  2067 TS
 2051  2068 TS
 2051  2069 TS
 2051  2070 TS
 2051  2072 TS
 2051  2073 TS
 2051  2074 TS
 2051  2075 TS
 2051  2077 TS
 2051  2078 TS
 2051  2080 TS
 2051  2356 RR
 2051  2386 TS
 2051  2387 TS
Editar: Ejecuté el siguiente programa pthreads simple y probé como el anterior. Lamentablemente, el comando chrt solo cambia la clase del hilo principal. Por favor ver más abajo.
$ ps -Lo pid,tid,class 3552
  PID   TID CLS
 3552  3552 TS
 3552  3553 TS
 3552  3554 TS
 3552  3555 TS
 3552  3556 TS
 3552  3557 TS
$ sudo chrt --rr -p 30 3552
 ...
$ ps -Lo pid,tid,class 3552
  PID   TID CLS
 3552  3552 RR
 3552  3553 TS
 3552  3554 TS
 3552  3555 TS
 3552  3556 TS
 3552  3557 TS
---- Programa ----
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5
void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   long k = 1;
   long a[10000];
   int i = 1;
  long b[10000];
   for (k = 0; k < 400000000; k++) {
        if (i == 9999) {
       i = 1;   
    } 
    a[i] = ((k + i) * (k - i))/2;
    a[i] = k/2;
        b[i] = i * 20;
    b[i] = a[i] - b[i];
        i++;
    int j = 0;
    for (j = 0; j < i; j++) {
        k = j - i;  
    } 
     } 
   pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}

-r(solo se usan dos veces), sugiero usar en su-rrrrrrrrrlugar ;-P-a, --all-tasks Set or retrieve the scheduling attributes of all the tasks (threads) for a given PID.Simplemente agregue este código dentro del código del hilo:
Esto le dará a cada hilo la máxima prioridad RR.
fuente