views:

229

answers:

4

Hi all,

Thanks for all the answers so far!

I am having a Dual Core processers and I would like to have all the processes running on core1 but one. I know now that I can use taskset to set all currently running to be bound to processor 1 for example. Now I would like that my OWN application is scheduled for execution on processor 2 instantly after launching the application. In other words, is there some way to tell the OS in my application that I would like to have this particular program to be executed on processor number 2?

Thank you so much, Mareika

+1  A: 

man taskset

Nikolai N Fetissov
THanks for your advice. However, is there also a way to specify in my application that it should run on the second core? So that it is automatically launched on the second core and I do not need to wait until after it has started with the execution?
Mareika
A: 

You can use:

taskset -c 1 -p 123

to let run process 123 on core 2.

tur1ng
You'll also have to do `taskset -c 0 -p <pid>` for every other running PID to fully achieve what the OP wanted.
caf
A: 

I would look for a way to limit the 'init' process to running on cpu 1.* Since CPU affinity is inherited, this should cause every other process on the system to also run on cpu 1, until you start your specific special process with cpu affinity set for cpu 2.

* Alternatively, after the system has started, you can re-assign the affinity of all currently running processes, but that seems less elegant.

Eric Seppanen
A: 

Take a look at this article:

http://www.linuxjournal.com/article/6799

Which covers the subject in detail.

In short, make sure 'init' is getting started with affinity for one proc (it's children will inherit), then you'll want to use:

// (Declaration got via 'man sched_setaffinity')
int sched_setaffinity(pid_t pid, size_t cpusetsize,
                         cpu_set_t *mask);

To set your process affinity just after your program starts up.

Aaron H.