How to assign one CPU to one process so that no other process can use that CPU while the process with that PID is running on that CPU?

1 Answer 1


From man taskset:

taskset is used to set or retrieve the CPU affinity of a running process given its PID 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 on any 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.

While this guarantees that the process will run only on a certain CPU (or a set of CPUs), the affinity setting does not guarantee that no other processes will run on those CPUs. To achieve this, I think you can change niceness (or nice level) of the process to its lowest value (1) - see man nice and man renice for details.

Setting the lowest nice level will guarantee that the process will not give the CPU to another task while running - however, the guarantee is not 100% (for example, if you have another process with the same priority in the system, both processess may be scheduled to share the CPU)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.