Linux – Is It Possible to set cpu affinity for particular user

central-processing-unitlinuxredhat

I mean is their any way we can set up cpu affinity for particular user, for all his currently running process or for process which he will start later?

Best Answer

Yes, this is possible.

I would execute the user's processes into a cgroup comprised of the CPU core(s) you wish to use. Depending on your version of RHEL (5 versus 6), you could use CPU shields via cpusets/cset in EL5 or try the cgroup approach documented in EL6. The latter example uses an /etc/cgrules.conf file which defines rules for cgroup resources (e.g. all of the processes belonging to Jerome will run in a specified cgroup). The former allows you to execute processes directly into a CPU shield.

For your example using cset, I would simply execute a bash shell for the user into the right CPU shield. All of their child proceses will be contained within. See here.