sched_getparam()

Получить текущие параметры планирования процесса

Прототип:

#include <sched.h>
int sched_getparam( pid_t pid,
struct sched_param *param );

Аргументы:

pid
The ID of the process whose scheduling parameters you want to get, or 0 to get them for the current process.
param
A pointer to a struct sched_param that the function fills with the scheduling parameters.

Библиотека:

libc

Описание:

The sched_getparam() function gets the current scheduling parameters (including the original and current priorities) of the process specified by pid, and puts them in the struct sched_param pointed to by param.

If pid is zero, function gets the parameters for the calling process.

Возвращаемое значение:

0
Успешное завершение.
-1
Возникла ошибка. Код ошибки записан в errno.

Коды ошибок:

EPERM
The calling process doesn't have sufficient privilege to get the scheduling parameters.
ESRCH
The process pid doesn't exist.

Примеры:

#include <sched.h>
#include <stdio.h>
#define PRIORITY_ADJUSTMENT 5
int main( void )
{
int max_priority;
struct sched_param param;
/* Find out the MAX priority for the FIFO Scheduler */
max_priority = sched_get_priority_max( SCHED_FIFO );
/* Find out what the current priority is. */
sched_getparam( 0, &param );
printf( "The assigned priority is %d.\n", param.sched_priority );
printf( "The current priority is %d.\n", param.sched_curpriority );
param.sched_priority = ((param.sched_curpriority + PRIORITY_ADJUSTMENT) <= max_priority) ?
(param.sched_curpriority + PRIORITY_ADJUSTMENT) : -1;
if ( param.sched_priority == -1 )
{
printf( "Cannot increase the priority by %d. Try a smaller value\n",
PRIORITY_ADJUSTMENT );
return (0);
}
sched_setscheduler( 0, SCHED_FIFO, &param );
sched_getparam( 0, &qparam );
printf( "The newly assigned priority is %d.\n", param.sched_priority );
printf( "The current priority is %d.\n", param.sched_curpriority );
return (0);
}

Классификация:

POSIX 1003.1 PS

Точка остановки потока
Нет
Обработчик прерываний
Нет
Обработчик сигналов
Да
В потоке
Да

Предостережения:

In a multithreaded program, sched_getparam() returns the scheduling parameters for thread 1 in the process pid, or for the calling thread if pid is 0.

Тематические ссылки:

struct sched_param, errno, getprio(), sched_get_priority_max(), sched_get_priority_min(), sched_getscheduler(), sched_setparam(), sched_setscheduler(), sched_yield(), setprio()




Предыдущий раздел: Описание API системной библиотеки