1TASKSET(1)                       User Commands                      TASKSET(1)
2
3
4

NAME

6       taskset - set or retrieve a process's CPU affinity
7

SYNOPSIS

9       taskset [options] mask command [argument...]
10
11       taskset [options] -p [mask] pid
12

DESCRIPTION

14       The taskset command is used to set or retrieve the CPU affinity of a
15       running process given its pid, or to launch a new command with a given
16       CPU affinity. CPU affinity is a scheduler property that "bonds" a
17       process to a given set of CPUs on the system. The Linux scheduler will
18       honor the given CPU affinity and the process will not run on any other
19       CPUs. Note that the Linux scheduler also supports natural CPU affinity:
20       the scheduler attempts to keep processes on the same CPU as long as
21       practical for performance reasons. Therefore, forcing a specific CPU
22       affinity is useful only in certain applications.
23
24       The CPU affinity is represented as a bitmask, with the lowest order bit
25       corresponding to the first logical CPU and the highest order bit
26       corresponding to the last logical CPU. Not all CPUs may exist on a
27       given system but a mask may specify more CPUs than are present. A
28       retrieved mask will reflect only the bits that correspond to CPUs
29       physically on the system. If an invalid mask is given (i.e., one that
30       corresponds to no valid CPUs on the current system) an error is
31       returned. The masks may be specified in hexadecimal (with or without a
32       leading "0x"), or as a CPU list with the --cpu-list option. For
33       example,
34
35       0x00000001
36           is processor #0,
37
38       0x00000003
39           is processors #0 and #1,
40
41       0xFFFFFFFF
42           is processors #0 through #31,
43
44       32
45           is processors #1, #4, and #5,
46
47       --cpu-list 0-2,6
48           is processors #0, #1, #2, and #6.
49
50       --cpu-list 0-10:2
51           is processors #0, #2, #4, #6, #8 and #10. The suffix ":N" specifies
52           stride in the range, for example 0-10:3 is interpreted as 0,3,6,9
53           list.
54
55       When taskset returns, it is guaranteed that the given program has been
56       scheduled to a legal CPU.
57

OPTIONS

59       -a, --all-tasks
60           Set or retrieve the CPU affinity of all the tasks (threads) for a
61           given PID.
62
63       -c, --cpu-list
64           Interpret mask as numerical list of processors instead of a
65           bitmask. Numbers are separated by commas and may include ranges.
66           For example: 0,5,8-11.
67
68       -p, --pid
69           Operate on an existing PID and do not launch a new task.
70
71       -h, --help
72           Display help text and exit.
73
74       -V, --version
75           Print version and exit.
76

USAGE

78       The default behavior is to run a new command with a given affinity
79       mask:
80           taskset mask command [arguments]
81
82       You can also retrieve the CPU affinity of an existing task:
83           taskset -p pid
84
85       Or set it:
86           taskset -p mask pid
87

PERMISSIONS

89       A user can change the CPU affinity of a process belonging to the same
90       user. A user must possess CAP_SYS_NICE to change the CPU affinity of a
91       process belonging to another user. A user can retrieve the affinity
92       mask of any process.
93

AUTHORS

95       Written by Robert M. Love.
96
98       Copyright © 2004 Robert M. Love. This is free software; see the source
99       for copying conditions. There is NO warranty; not even for
100       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
101

SEE ALSO

103       chrt(1), nice(1), renice(1), sched_getaffinity(2), sched_setaffinity(2)
104
105       See sched(7) for a description of the Linux scheduling scheme.
106

REPORTING BUGS

108       For bug reports, use the issue tracker at
109       https://github.com/util-linux/util-linux/issues.
110

AVAILABILITY

112       The taskset command is part of the util-linux package which can be
113       downloaded from Linux Kernel Archive
114       <https://www.kernel.org/pub/linux/utils/util-linux/>.
115
116
117
118util-linux 2.38                   2022-02-17                        TASKSET(1)
Impressum