Is there any way I can trick a program into thinking the system has fewer processors? To explain: I am debugging a program that creates as many threads as it has processors, using sysconf(_SC_NPROCESSORS_CONF);. I'd like to test it using only one threat. Strictly for convenience, I'd like to know if there's a way I can trick the program into thinking the computer only has one processor, to avoid having to add a command line option or changing the code to temporarily only create one thread.
Asked
Active
Viewed 1,043 times
1
Claudiu
- 205
- 2
- 6
-
2Related: http://unix.stackexchange.com/questions/23106/limit-process-to-one-cpu-core – Mark Plotnick Jan 26 '15 at 19:30
-
1You can override any library/system call with `LD_PRELOAD` or `ptrace`. I don't know if there's a ready-made solution. – Gilles 'SO- stop being evil' Jan 26 '15 at 20:47
-
1You could run it under a virtual machine that only has one virtual processor. – Barmar Jan 26 '15 at 22:12
1 Answers
1
Under FreeBSD (>=7.1), you can use the /usr/bin/cpuset command eg :
# cpuset -l 0,2 -c -p <pid>
Under Linux, see : http://man7.org/linux/man-pages/man7/cpuset.7.html