3 .\" Copyright (C) 2004 Robert Love
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License,
7 .\" version 2, as published by the Free Software Foundation.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public License along
20 .\" with this program; if not, write to the Free Software Foundation, Inc.,
21 .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 .TH TASKSET 1 "August 2014" "util-linux" "User Commands"
25 taskset \- set or retrieve a process's CPU affinity
29 .IR mask\ command\ [ argument ...]
38 is used to set or retrieve the CPU affinity of a running process given its
39 \fIpid\fR, or to launch a new \fIcommand\fR with a given CPU affinity.
41 scheduler property that "bonds" a process to a given set of CPUs on the system.
42 The Linux scheduler will honor the given CPU affinity and the process will not
43 run on any other CPUs. Note that the Linux scheduler also supports natural
44 CPU affinity: the scheduler attempts to keep processes on the same CPU as long
45 as practical for performance reasons. Therefore, forcing a specific CPU
46 affinity is useful only in certain applications.
48 The CPU affinity is represented as a bitmask, with the lowest order bit
49 corresponding to the first logical CPU and the highest order bit corresponding
50 to the last logical CPU. Not all CPUs may exist on a given system but a mask
51 may specify more CPUs than are present. A retrieved mask will reflect only the
52 bits that correspond to CPUs physically on the system. If an invalid mask is
53 given (i.e., one that corresponds to no valid CPUs on the current system) an
54 error is returned. The masks may be specified in hexadecimal (with or without
55 a leading "0x"), or as a CPU list with the
64 is processors #0 and #1,
67 is processors #0 through #31,
70 is processors #1, #4, and #5,
72 .B \-\-cpu\-list\ 0-2,6
73 is processors #0, #1, #2, and #6.
75 .B \-\-cpu\-list\ 0-10:2
76 is processors #0, #2, #4, #6, #8 and #10. The suffix ":N" specifies stride in
77 the range, for example 0-10:3 is interpreted as 0,3,6,9 list.
82 returns, it is guaranteed that the given program has been scheduled to a legal
86 .BR \-a ,\ \-\-all\-tasks
87 Set or retrieve the CPU affinity of all the tasks (threads) for a given PID.
89 .BR \-c ,\ \-\-cpu\-list
90 Interpret \fImask\fR as numerical list of processors instead of a bitmask.
91 Numbers are separated by commas and may include ranges. For example:
95 Operate on an existing PID and do not launch a new task.
97 .BR \-V ,\ \-\-version
98 Display version information and exit.
101 Display help text and exit.
104 The default behavior is to run a new command with a given affinity mask:
107 .IR command\ [ arguments ]
109 You can also retrieve the CPU affinity of an existing task:
117 A user can change the CPU affinity of a process belonging to the same user.
120 to change the CPU affinity of a process belonging to another user.
121 A user can retrieve the affinity mask of any process.
123 Written by Robert M. Love.
125 Copyright \(co 2004 Robert M. Love.
126 This is free software; see the source for copying conditions. There is NO
127 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
132 .BR sched_getaffinity (2),
133 .BR sched_setaffinity (2)
137 for a description of the Linux scheduling scheme.
139 The taskset command is part of the util-linux package and is available from
140 https://www.kernel.org/pub/linux/utils/util-linux/.