Is It Possible to set cpu affinity for particular user?

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.


The following small bash-script will do it:

u=username # do not set this to root!
c=logical processor number you want to bind to
for p in $(pgrep -u $u)
  do
    taskset -cp $c $p
done

Children of the bound processes will stay bound to that cpu-set.