CPU Affinity - Soft vs Hard
There are two ways to do this, however you have to remember that both cores are each treated as their own CPU. So this will apply if you have one Dual-Core CPU, or two separate CPUs.
You have to at least have glibc 2.3.1 and a minimum of kernel 2.5.8-pre3. Plus, that kernel has to be compiled to be SMP-aware.
To find out, try typing "uname -a" and if "-smp" is listed, you're off to a great start. If not, look for the file /proc/config.gz or /proc/.config
and "cat /proc/<filename> | grep -i smp" to see if it's set.
Barring that, just cross your fingers, most newer Linux distributions come with SMP-aware kernels, so if you're running Red Hat 9 or higher, you're good.
Most schedulers in the kernel will try to move processes around between CPUs to try and keep their utilization even. This is to prevent any single CPU from becoming overloaded.
Most schedulers in 2.5 and 2.6 kernels have great "natural" affinity. The 2.4 scheduler had a pretty bad implementation, and would "ping-pong" processes around unnecessarily, almost to the point of hilarity.
If you're running a Red Hat based Linux distribution (like CentOS, for example), you'll have to make sure you have the "taskset" command.
With that, you can set the masks you need so you can bind process IDs to one or more CPUs.
It's fairly easy to use, for example, to bind process ID 12345 to the first CPU, just type the following;
taskset 0x00000001 -p 12345
Or if you don't need to impress the boss, just use the simpler form;
taskset -c 1 -p 12345
You can also bind a process to more than one CPU;
taskset -c 1,2 -p 12345
Hope this helps!