Forrest logo
back to the taskset tool

taskset:tldr:b2078

taskset: Set a running process' CPU affinity by PID.
$ taskset --pid --cpu-list ${cpu_id} ${pid}
try on your machine

The command "taskset --pid --cpu-list ${cpu_id} ${pid}" is used to associate a specific CPU or a group of CPUs with a given process ID (PID) on Linux.

Let's break down the command and understand its components:

  • "taskset" is a command-line utility in Linux that sets or retrieves the CPU affinity of a running process.
  • "--pid" is an option to specify that the PID parameter is used to identify the process.
  • "--cpu-list" is an option to specify the CPU or CPUs to assign to the process. "${cpu_id}" is a placeholder for the CPU or CPUs you want to assign, and it could be a comma-separated list or a range of CPUs.
  • "${pid}" is a placeholder for the Process ID of the process you want to modify.

By executing this command with the appropriate values for "${cpu_id}" and "${pid}", you can control which CPU or CPUs the specified process can run on. This can be useful in situations where you want to optimize CPU usage or isolate a process to a specific set of CPUs.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the taskset tool