Wednesday, August 12, 2009


  • taskset is used to set or retrieve the CPU affinity of a running process given itsPID or to launch a new COMMAND with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system.
  • The Linux scheduler will honor the given CPU affinity and the process will not run onany other CPUs.
  • Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons.
  • Therefore, forcing a specific CPU affinity is useful only in certain applications.

Open 2 ssh sessions

Session 1) Run top command
After loading ‘top’ press 1 (one) to switch to SMP view, which will show each CPU usage.

Session 2) taskset command syntax is
taskset -cp $CPU $PID
-c cpuid
-p process id

Example on 8 CPU system affinitize top to 7th CPU

taskset -cp 07 `ps aux | grep top | head -n1 | awk '{printf "%s\n", $2}'`

No comments: