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       taskset [options] -p [mask] pid
11

DESCRIPTION

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

OPTIONS

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

USAGE

72       The  default  behavior  is  to  run a new command with a given affinity
73       mask:
74              taskset mask command [arguments]
75
76       You can also retrieve the CPU affinity of an existing task:
77              taskset -p pid
78
79       Or set it:
80              taskset -p mask pid
81

PERMISSIONS

83       A user can change the CPU affinity of a process belonging to  the  same
84       user.  A user must possess CAP_SYS_NICE to change the CPU affinity of a
85       process belonging to another user.  A user can  retrieve  the  affinity
86       mask of any process.
87

AUTHORS

89       Written by Robert M. Love.
90
92       Copyright © 2004 Robert M. Love.  This is free software; see the source
93       for copying conditions.  There  is  NO  warranty;  not  even  for  MER‐
94       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
95

SEE ALSO

97       chrt(1), nice(1), renice(1), sched_getaffinity(2), sched_setaffinity(2)
98
99       See sched(7) for a description of the Linux scheduling scheme.
100

AVAILABILITY

102       The  taskset command is part of the util-linux package and is available
103       from https://www.kernel.org/pub/linux/utils/util-linux/.
104
105
106
107util-linux                        August 2014                       TASKSET(1)
Impressum