sched_setattr(2) System Calls Manual sched_setattr(2) sched_setattr, sched_getattr - C (libc, -lc) #include /* SCHED_* */ #include /* SYS_* */ #include int syscall(SYS_sched_setattr, pid_t pid, struct sched_attr *attr, unsigned int flags); int syscall(SYS_sched_getattr, pid_t pid, struct sched_attr *attr, unsigned int size, unsigned int flags); : glibc , syscall(2). sched_setattr() sched_setattr() pid. pid , . Linux <<>> (. . ) , policy: SCHED_OTHER ; SCHED_BATCH <<>> ; SCHED_IDLE . << >>, , , . , , sched(7). , policy: SCHED_FIFO << -- >>; SCHED_RR . Linux : SCHED_DEADLINE ; sched(7). attr , , . : struct sched_attr { u32 size; /* Size of this structure */ u32 sched_policy; /* Policy (SCHED_*) */ u64 sched_flags; /* Flags */ s32 sched_nice; /* Nice value (SCHED_OTHER, SCHED_BATCH) */ u32 sched_priority; /* Static priority (SCHED_FIFO, SCHED_RR) */ /* For SCHED_DEADLINE */ u64 sched_runtime; u64 sched_deadline; u64 sched_period; /* Utilization hints */ u32 sched_util_min; u32 sched_util_max; }; sched_attr: size sizeof(struct sched_attr). , , <<0>>. , , 0; , sched_setattr() E2BIG size . sched_attr . , , , sched_attr. , , sched_attr , , , . sched_policy SCHED_*, . sched_flags , : SCHED_FLAG_RESET_ON_FORK , fork(2), . sched(7). SCHED_FLAG_RECLAIM ( Linux 4.13) SCHED_DEADLINE , . SCHED_FLAG_DL_OVERRUN ( Linux 4.16) (run-time overrun) SCHED_DEADLINE. () . SIGXCPU, . SIGXCPU ( signal(7)), . , . , sched_setattr() . , , , , , . SCHED_FLAG_UTIL_CLAMP_MIN SCHED_FLAG_UTIL_CLAMP_MAX ( Linux 5.3) These flags indicate that the sched_util_min or sched_util_max fields, respectively, are present, representing the expected minimum and maximum utilization of the thread. The utilization attributes provide the scheduler with boundaries within which it should schedule the thread, potentially informing its decisions regarding task placement and frequency selection. sched_nice , sched_policy SCHED_OTHER SCHED_BATCH. -20 ( ) +19 ( ); sched(7). sched_priority , sched_policy SCHED_FIFO SCHED_RR. sched_get_priority_min(2) sched_get_priority_max(2). 0. sched_runtime <> . . SCHED_DEADLINE; sched(7). sched_deadline <> . . sched_period <> . . sched_util_min sched_util_max ( Linux 5.3) These fields specify the expected minimum and maximum utilization, respectively. They are ignored unless their corresponding SCHED_FLAG_UTIL_CLAMP_MIN or SCHED_FLAG_UTIL_CLAMP_MAX is set in sched_flags. Utilization is a value in the range [0, 1024], representing the percentage of CPU time used by a task when running at the maximum frequency on the highest capacity CPU of the system. This is a fixed point representation, where 1024 corresponds to 100%, and 0 corresponds to 0%. For example, a 20% utilization task is a task running for 2ms every 10ms at maximum frequency and is represented by a utilization value of 0.2 * 1024 = 205. A task with a minimum utilization value larger than 0 is more likely scheduled on a CPU with a capacity big enough to fit the specified value. A task with a maximum utilization value smaller than 1024 is more likely scheduled on a CPU with no more capacity than the specified value. A task utilization boundary can be reset by setting its field to UINT32_MAX (since Linux 5.11). flags ; 0. sched_getattr() sched_getattr() pid. pid , . size sched_attr, . sched_attr EINVAL. sched_attr, attr. attr.size sched_attr. If the caller-provided attr buffer is larger than the kernel's sched_attr structure, the additional bytes in the user-space structure are not touched. If the caller-provided structure is smaller than the kernel sched_attr structure, the kernel will silently not return any values which would be stored outside the provided space. As with sched_setattr(), these semantics allow for future extensibility of the interface. flags ; 0. On success, sched_setattr() and sched_getattr() return 0. On error, -1 is returned, and errno is set to indicate the error. sched_getattr() sched_setattr() : EINVAL attr NULL; pid ; flags 0. ESRCH pid . sched_getattr() : E2BIG , size attr, . EINVAL size; , sched_attr (48 ) . sched_setattr() : E2BIG , size attr, . EBUSY SCHED_DEADLINE, sched(7). EINVAL attr.sched_policy is not one of the recognized policies. EINVAL attr.sched_flags contains a flag other than SCHED_FLAG_RESET_ON_FORK. EINVAL attr.sched_priority . EINVAL attr.sched_policy is SCHED_DEADLINE, and the deadline scheduling parameters in attr are invalid. EINVAL attr.sched_flags contains SCHED_FLAG_UTIL_CLAMP_MIN or SCHED_FLAG_UTIL_CLAMP_MAX, and attr.sched_util_min or attr.sched_util_max are out of bounds. EOPNOTSUPP SCHED_FLAG_UTIL_CLAMP was provided, but the kernel was not built with CONFIG_UCLAMP_TASK support. EPERM . EPERM , pid, ( sched_setaffinity(2)). Linux. Linux 3.14. glibc does not provide wrappers for these system calls; call them using syscall(2). sched_setattr() sched_setscheduler(2), sched_setparam(2), nice(2) ( , ) setpriority(2). , sched_getattr() sched_getscheduler(2), sched_getparam(2) () getpriority(2). Linux 3.15, sched_setattr() EFAULT, E2BIG , . Up to Linux 5.3, sched_getattr() failed with the error EFBIG if the in-kernel sched_attr structure was larger than the size passed by user space. chrt(1), nice(2), sched_get_priority_max(2), sched_get_priority_min(2), sched_getaffinity(2), sched_getparam(2), sched_getscheduler(2), sched_rr_get_interval(2), sched_setaffinity(2), sched_setparam(2), sched_setscheduler(2), sched_yield(2), setpriority(2), pthread_getschedparam(3), pthread_setschedparam(3), pthread_setschedprio(3), capabilities(7), cpuset(7), sched(7) () Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . sched_setattr(2)