Linux – How to force a process to run on a single thread only with numactl

linux

My local machines has multiple CPUs, each has multiple cores, and each can support multiple threads. I have a multithreading process that I want to force to run on a single thread only. I understand numactrl can do that.

How can I use numactl to force the process to run only on a single thread? Alternatively, is there an even simpler built-in utility that can do that?

Best Answer

numactl --physcpubind=+1 /path/to/your/executable

this should run your process on the second core/cpu assigned to your chipset (index 1). see the Examples section of the man page for more details: http://linux.die.net/man/8/numactl

Edit: I should point out, that this means the program will run at most one thread concurrently, but it does not mean that the entire process will be composed of only one thread. if the program is written to spawn a new thread, it will do so, but it will execute on the same core/cpu as the rest of the process. a slim distinction, but potentially important nonetheless.

Related Question