As mentioned in the answer by @Ipor to limit program to one CPU hardware core/thread one may use taskset 1 prog [args]
Also, there is a way to explicitly prohibit a process from cloning (not sure about apps that use fork
though, checked only for clone
sys call).
The program to limit number of processes a program can have (threads) is prlimit --nproc=1 prog [args]
. I've tried to use it with rsync
and got "fork unavailable... error in IPC" and the end - rsync
is written not to work as one thread.
strace prlimit --nproc=1 rsync
Running strace
has shown as described in SO link below return value from clone
call is -1 EAGAIN (resource temporary unavailable).
P.S. idea taken from https://stackoverflow.com/questions/38637451/is-there-a-way-force-a-program-to-use-only-1-thread.
std::thread::hardware_concurrency
,sysconf(_SC_NPROCESSORS_ONLN)
,/proc/cpuinfo
,cpuid
, etc) there may be different approaches to fake the core count. That said, as suggested by @JohanMyréen, at that point it may be easier to hardcode how many threads to spawn.