Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how linux uses multiple processors

Posted on 2011-05-03
8
Medium Priority
?
387 Views
Last Modified: 2012-05-11
Hello

My machine has 8 processors. If i start 7 command prompts and run a perl script from each is there anyway I can ensure each script goes to a separate processor?

If i had a perl programmer which created 7 threads and each thread ran the code in question will each thread use a separate processor behind the scenes or do i have to handle that myself?

thanks
0
Comment
Question by:andieje
  • 4
  • 3
8 Comments
 
LVL 30

Accepted Solution

by:
Kerem ERSOY earned 2000 total points
ID: 35517522
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 35517536
Please check this article too with insight details of using CPU Affinity.

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

Cheers,
K.
0
 

Author Comment

by:andieje
ID: 35692146
looking at those pages it seems i have to start the process first and then assign them to a processor?

can i assign memory too?
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:andieje
ID: 35692691
this gives me an error

  PID TTY          TIME CMD
 2667 pts/0    00:00:00 bash
 5055 pts/0    00:00:00 test_scr
 5058 pts/0    00:00:00 ps

oscar$ taskset 0x00000001 -p 5055
execvp: No such file or directory
failed to execute -p
0
 

Author Comment

by:andieje
ID: 35692860
ok - it seems that page is old and the command syntax has changed. It is now taskset -cp $CPU $PID.

One of the comments on the page says:

"However, if I begin a new cpu intensive process and assign it an affinity before running it, then I can see changes in the output of ‘top’. any clues to this? "

How can you assign a process an affinity before running it? How would you have the PID for it?
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 35693374
In fact you don't see them in "top" you'll have to download iand install "htop" for this.

Cheers,
K.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 35693450
> looking at those pages it seems i have to start the process first and then assign them to a processor?
>
> can i assign memory too?

what do you mean by assigning memory ??


> oscar$ taskset 0x00000001 -p 5055
> execvp: No such file or directory
> failed to execute -p

Please use this syntax instead :

taskset -cp 0x00000001 5055

0
 
LVL 8

Expert Comment

by:JIEXA
ID: 35715257
Let's not start talking about CPU affinity.

If you start 6 processes or threads on an idle 8-CPU machine, and each thread/process is CPU hungry, you might use 600% of CPU (6 CPUs out of 8).
If one of these processes/threads waits for I/O, for example, then another one waits for I/O, and then both are ready to run on CPU, their CPU might been switched. If it's what you need, you don't need to bother with CPU affinity.

To ensure that you used more than 1 CPU, you need to get resource usage (getrusage() call) for CPU time, and for a given wallclock time, the CPU usage for all threads should be greater than the wallclock time passed.

Affinity is good if your threads/processes are CPU hungry and the price of context switch or migration between CPUs is high (for example, on NUMA architecture).
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question