LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-15-2007, 01:22 PM   #1
danfou
Member
 
Registered: Nov 2006
Posts: 46

Rep: Reputation: 15
cpus for one process


How to limit the number of cpus that my process can use?

I look into taskset, but still have no idea?

Can someone give some detailed help, say an example command?

Thanks.
 
Old 05-15-2007, 01:28 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
I might use cpusets (I presume you’re using linux).
 
Old 05-15-2007, 01:44 PM   #3
Marsolin
Member
 
Registered: Jul 2005
Posts: 124

Rep: Reputation: 15
You could try cpulimit.
 
Old 05-15-2007, 02:55 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Btw, what exactly did you not like about taskset? Let’s say I have four cpus. If I give each cpu a binary mask, I get something like this (just for fun, I start counting from cpu1, even though normally counting starts at cpu0):
Code:
CPU#  MASK  DECIMAL
cpu1  0001     1
cpu2  0010     2
cpu3  0100     4
cpu4  1000     8
What if I want a process to have affinity only for cpu1 and cpu4? I would OR the masks together for their combined mask:
Code:
cpu1 | cpu4 =
0001 | 1000 = 1001
            = 9
So let’s say this process whose affinity I’m setting has pid 1234. I would do something like this to limit its affinity to cpu1 and cpu4:
Code:
# taskset -p 9 1234
(NOTE: it is somewhat strange that the PID does not immediately follow the “-p” flag.)
 
Old 05-15-2007, 03:06 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Marsolin
You could try cpulimit.
cpulimit (AFAICT) will limit the “percentage of cpu power” a process is able to use. This does not necessarily mean the given process will be confined to one cpu (though it should most of the time).
 
Old 06-21-2007, 10:37 AM   #6
killerforce
LQ Newbie
 
Registered: Mar 2007
Posts: 12

Rep: Reputation: 0
hi OSOR

Code:
Btw, what exactly did you not like about taskset? Let’s say I have four cpus. If I give each cpu a binary mask, I get something like this (just for fun, I start counting from cpu1, even though normally counting starts at cpu0):
Code:

CPU# MASK DECIMAL 
cpu1 0001 1 
cpu2 0010 2 
cpu3 0100 4 
cpu4 1000 8

What if I want a process to have affinity only for cpu1 and cpu4? I would OR the masks together for their combined mask:
Code:

cpu1 | cpu4 = 0001 | 1000 = 1001 = 9

So let’s say this process whose affinity I’m setting has pid 1234. I would do something like this to limit its affinity to cpu1 and cpu4:
Code:

# taskset -p 9 1234
Quote:
Now where do you set those binary mask to the CPUs. I'm using slackware 11 with kernel 2.6.17.13. Where would I set that ?


Quote:
And if you set cpu affinity for a process using its pid, then after reboot the pid of that process might change. So how is it going to work ? Please give me some advice.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a process on more CPUs simonj82 Linux - Server 2 11-09-2006 08:51 PM
CPUs totallynewguy Linux - Hardware 3 08-29-2005 10:06 PM
Via CPUs 3dmike Linux - Hardware 2 03-22-2004 12:39 PM
2 CPUs jhirshon Linux - Newbie 2 01-31-2004 05:59 PM
What CPUs does everyone use? Guru3 Linux - Hardware 43 01-22-2004 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration