How can I set CPU affinity for the specific program (say gzip) to always run on specific core or cores (core 1, for example)?I read about taskset, but can it be used before program is actually used and creates a process?
Set CPU affinity for the specific program?
cpu;cpu frequency;cpu usage
You can't set the affinity for all invocations of an executable. The affinity is managed by the kernel and inherited from parent process to child process, there's no mechanism that changes the affinity of a process when an executable is executed.If you want all invocations of gzip to run on CPU 1, put a wrapper script called gzip ahead of the real one in the PATH, e.g. ~/bin/gzip:#!/bin/shexec taskset 1 /bin/gzip $@But this strikes me as completely useless. Explicitly setting a process's affinity usually makes things slower. It can sometimes be useful to confine a CPU-intensive task to certain processors and leave the system more reactive, though nice usually does a better job overall. But doing that indiscriminately for all the invocations of an executable sounds like an XY problem.