I have an Intel E5620 processor. I have used cat /proc/[pid]/stat
to determine what processor the process was last run on (39th field). How can I ensure that a process is dedicated to a processor (I have 8 available) or better yet, how can I dedicate a process to a core (I have 4)?
![](../../users/profiles/26514.webp)
- 591
- 7
- 25
-
6Why do you want to do this? The CPU scheduling in most operating systems these days is far superior to a blunt instrument `CPU C is only available to process P` type of assignment. – voretaq7 Oct 06 '11 at 17:51
-
1@voretaq7: Because I have a need to do some dedicated processing. I am porting a PowerPC application to linux. Previously it was housed in a VME chassis. – Engineer2021 Oct 06 '11 at 17:53
-
1Do you need to tie the process to a processor (that may be used by other programs too), or do you want to dedicate the processor to a process (so no other processes can get to that CPU)? And again - ***Why*** do you want to do this? (what is "dedicated processing"? Why can't it be moved from CPU to CPU?) – voretaq7 Oct 06 '11 at 18:02
-
@voretaq7: Because I have a process to consume 200MB/s data from PCIe and I need to consume this very fast. I don't want anyone else on that processor. – Engineer2021 Oct 06 '11 at 18:07
-
See my answer below. As @MikeyB noted you should not be trying to outsmart the scheduler - There are proper ways to ensure that you always have CPU cycles when you want them, and they make the scheduler work for you rather than against you. – voretaq7 Oct 06 '11 at 18:16
-
An easier way for a human to see which cores are running a process is to "ps -Lo pid -Lo psr -Lo command" – rbanffy Sep 10 '22 at 16:54
5 Answers
Based on your comment on MikeyB's answer you're trying to solve this the wrong way IMHO --
Both numactl
and taskset
will lock your process to a CPU, but they won't keep other processes off that CPU.
If someone else is on that CPU when your process needs it you will have to wait.
A better solution is to set your process' nice
value to something that will cause it to aggressively grabt he CPU (something like -20), and if that's still not enough set your process to realtime priority
using rtprio, and let the scheduler do what it has to do to make sure that your process always has CPU cycles when it asks for them.
Trying to outsmart the scheduler is, as MikeyB pointed out, generally a Bad Idea. Let it do what it's designed to do, and ask for CPU cycles the RIGHT way (nice
values and rtprio
).
![](../../users/profiles/32986.webp)
- 79,345
- 17
- 128
- 213
-
`nice` is a good idea, but I have processes running via rc.local. Not sure how to `su` to root to ensure that the processes run at the highest value in some instances at startup. I guess I should ask another question regarding that. – Engineer2021 Oct 06 '11 at 18:18
-
I don't see rtprio on my RHEL5.3 install. IS there a RPM for this? – Engineer2021 Oct 06 '11 at 18:23
numactl
allows you to bind a process to a core or physical CPU as well as forcing a memory allocation policy.
Usually, this is not necessary. Stop trying to outsmart the scheduler.
![](../../users/profiles/2101.webp)
- 38,725
- 10
- 102
- 186
-
1I have 200MB/s of data I need to consume through the PCIe slot on a 2.4 GHz processor. I need to be able to consume this very fast and control where the processes are running. – Engineer2021 Oct 06 '11 at 17:59
-
To bind a process PID 12345 to the first processor, try this:
# taskset -p 0x00000001 12345
![](../../users/profiles/59925.webp)
- 50,327
- 19
- 152
- 213
-
I'm getting `execvp: No such file or directory failed to execute -p` – Engineer2021 Oct 06 '11 at 18:00
-
-
hmm, this answer here seemed to work : http://superuser.com/questions/240996/execvp-no-such-file-or-directory-when-attempting-taskset-on-a-running-process – Engineer2021 Oct 06 '11 at 18:07