5

I have a command to run (in this case is a php5 script) and I would like to know if there is something to run this command and select the core to be runed.

What I want to do is to run 1 command per each core to use the multiple cores of my server.

Any idea? Or I have to rewrite the script in other languages with multicore support and develop the core control directly in the script?

Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58
enedebe
  • 1,006
  • 3
  • 11
  • 17
  • If you're on Linux and you really want to run something on a specific core, numactl will do this. Otherwise, as below, run 2 copies at once and they'll be assigned to different cores for you. – pjc50 Feb 24 '12 at 10:55
  • What OS are you running? – phemmer Feb 24 '12 at 13:10

3 Answers3

9

The command to run or assign a specific command to a particular core is taskset.

Embed it in your startup script or use from the command line like:

taskset -c 0,5 command_name -c is a list of one or more CPUs to run the command on; in this case, core 0 and 5.

You can also modify the core assignment of a running process by specifying a PID with taskset.

But you may also want to see: Assigning Processes to CPU Cores

ewwhite
  • 194,921
  • 91
  • 434
  • 799
6

Your kernels scheduler will do this just fine all by itself and doesn't need a user to do his work.

Sven
  • 97,248
  • 13
  • 177
  • 225
1

What I want to do is to run 1 command per each core to use the multiple cores of my server.

Multi core for beginners: the system scheduler takes care of that.

StartX instances, with X being the number of hardware threadyyou ahve (cores, or real cores x2 for intel with hyperthreading.

If your program uses only one core, nothign you do will optimize it, given that you use an OS that is NUMA aware on a NUMA archtiecture.

TomTom
  • 50,857
  • 7
  • 52
  • 134