| SCHED_SETAFFINITY(2) | Linux Programmer's Manual | SCHED_SETAFFINITY(2) |
NAME
sched_setaffinity, sched_getaffinity - set and get a process's CPU affinity mask
SYNOPSIS
#include <sched.h>
int sched_setaffinity(pid_t pid, unsigned int len, unsigned long *mask);
int sched_getaffinity(pid_t pid, unsigned int len, unsigned long *mask);
DESCRIPTION
sched_setaffinity sets the CPU affinity mask of the process denoted by pid. If pid is zero, then the current process is used.
The affinity mask is represented by the bitmask stored in mask. The least significant bit corresponds to the first logical processor number on the system, while the most significant bit corresponds to the last logical processor number on the system. A set bit corresponds to a legally schedulable CPU while an unset bit corresponds to an illegally schedulable CPU. In other words, a process is bound to and will only run on processors whose corresponding bit is set. Usually, all bits in the mask are set.
If the process specified by pid is not curently running on one of the CPUs specified in mask, then that process is migrated to one of the CPUs specified in mask.
The argument len is the length (in bytes) of the data pointed to by mask. Normally this is the size of a word on the system. For compatibility with future versions of the Linux kernel, since this size can change, the bitmask supplied must be at least as large as the affinity mask stored in the kernel.
The function sched_getaffinity writes into the pointer supplied by mask that has size len the affinity mask of process pid. If pid is zero, then the mask of the current process is returned.
RETURN VALUE
On success, sched_setaffinity returns 0. On error, -1 is returned, and errno is set appropriately.
On success, sched_getaffinity always returns the size (in bytes) of the affinity mask used by the kernel. On error, -1 is returned, and errno is set appropriately.
ERRORS
- EFAULT
- A supplied memory address was invalid.
- EINVAL
- The affinity bitmask mask contains no processors that are physically on the system, or the length len is smaller than the size of the affinity mask used by the kernel.
- EPERM
- The calling process does not have appropriate privileges. The process calling sched_setaffinity needs an effective user ID equal to the user ID or effective user ID of the process identified by pid, or it must possess the CAP_SYS_NICE capability.
- ESRCH
- The process whose ID is pid could not be found.
NOTES
The affinity mask is actually a per-thread attribute that can be adjusted independently for each of the threads in a thread group. The value returned from a call to gettid(2) can be passed in the argument pid.
HISTORY
The affinity syscalls were introduced in Linux kernel 2.5.8. The library calls were introduced in glibc 2.3, and are still in glibc 2.3.2. Later glibc 2.3.2 development versions changed this interface to one without the len field, and still later versions reverted again. The glibc prototype is now
/* Set the CPU affinity for a task */
extern int sched_setaffinity (pid_t pid, size_t cpusetsize,
const cpu_set_t *cpuset);
/* Get the CPU affinity for a task */
extern int sched_getaffinity (pid_t pid, size_t cpusetsize,
cpu_set_t *cpuset);
SEE ALSO
clone(2), getpriority(2), gettid(2), nice(2), sched_get_priority_max(2), sched_get_priority_min(2), sched_getscheduler(2), sched_setscheduler(2), setpriority(2), capabilities(7)
sched_setscheduler(2) has a description of the Linux scheduling scheme.
| 2005-05-03 | Linux |
Different Versions of this Page:
- Version 6.17 (latest)
- Version 6.16
- Version 6.15
- Version 6.14
- Version 6.13
- Version 6.12
- Version 6.11
- Version 6.10
- Version 6.9.1
- Version 6.9
- Version 6.8
- Version 6.7
- Version 6.06
- Version 6.05.01
- Version 6.05
- Version 6.04
- Version 6.03
- Version 6.02
- Version 6.01
- Version 6.00
- Version 5.13
- Version 5.12
- Version 5.11
- Version 5.10
- Version 5.09
- Version 5.08
- Version 5.07
- Version 5.06
- Version 5.05
- Version 5.04
- Version 5.03
- Version 5.02
- Version 5.01
- Version 5.00
- Version 4.16
- Version 4.15
- Version 4.14
- Version 4.13
- Version 4.12
- Version 4.10
- Version 4.09
- Version 4.08
- Version 4.07
- Version 4.06
- Version 4.05
- Version 4.04
- Version 4.03
- Version 4.02
- Version 4.01
- Version 4.00
- Version 3.83
- Version 3.82
- Version 3.81
- Version 3.80
- Version 3.79
- Version 3.78
- Version 3.77
- Version 3.76
- Version 3.75
- Version 3.74
- Version 3.73
- Version 3.72
- Version 3.71
- Version 3.70
- Version 3.69
- Version 3.68
- Version 3.67
- Version 3.66
- Version 3.65
- Version 3.64
- Version 3.63
- Version 3.62
- Version 3.61
- Version 3.60
- Version 3.59
- Version 3.58
- Version 3.57
- Version 3.56
- Version 3.55
- Version 3.54
- Version 3.53
- Version 3.52
- Version 3.49
- Version 3.48
- Version 3.47
- Version 3.46
- Version 3.45
- Version 3.44
- Version 3.43
- Version 3.42
- Version 3.41
- Version 3.40
- Version 3.39
- Version 3.38
- Version 3.37
- Version 3.36
- Version 3.35
- Version 3.34
- Version 3.33
- Version 3.32
- Version 3.31
- Version 3.30
- Version 3.29
- Version 3.28
- Version 3.27
- Version 3.26
- Version 3.25
- Version 3.24
- Version 3.23
- Version 3.22
- Version 3.21
- Version 3.20
- Version 3.17
- Version 3.16
- Version 3.15
- Version 3.14
- Version 3.13
- Version 3.12
- Version 3.11
- Version 3.10
- Version 3.09
- Version 3.08
- Version 3.07
- Version 3.06
- Version 3.05
- Version 3.04
- Version 3.03
- Version 3.02
- Version 3.01
- Version 3.00
- Version 2.80
- Version 2.79
- Version 2.78
- Version 2.77
- Version 2.76
- Version 2.75
- Version 2.74
- Version 2.73
- Version 2.72
- Version 2.71
- Version 2.70
- Version 2.69
- Version 2.68
- Version 2.67
- Version 2.66
- Version 2.65
- Version 2.64
- Version 2.63
- Version 2.62
- Version 2.61
- Version 2.60
- Version 2.59
- Version 2.58
- Version 2.57
- Version 2.56
- Version 2.55
- Version 2.54
- Version 2.53
- Version 2.52
- Version 2.51
- Version 2.50
- Version 2.49
- Version 2.48
- Version 2.47
- Version 2.46
- Version 2.45
- Version 2.44
- Version 2.43
- Version 2.42
- Version 2.41
- Version 2.40
- Version 2.39
- Version 2.38
- Version 2.37
- Version 2.36
- Version 2.35
- Version 2.34
- Version 2.33
- Version 2.32
- Version 2.31
- Version 2.30
- Version 2.29
- Version 2.28
- Version 2.27
- Version 2.26
- Version 2.25
- Version 2.24
- Version 2.23
- Version 2.22
- Version 2.21
- Version 2.20
- Version 2.19
- Version 2.18
- Version 2.17
- Version 2.16
- Version 2.15
- Version 2.14
- Version 2.13
- Version 2.12
- Version 2.11
- Version 2.10
- Version 2.09
- Version 2.08
- Version 2.07
- Version 2.06
- Version 2.05
- Version 2.04
- Version 2.03
- Version 2.02
- Version 2.01
- Version 2.00