How to run a program with only one CPU core?
I'm trying to run a bunch of scripts related to a gaming server in Terminator. The only problem is when I do this, Terminator detects all my CPU cores and the PC lags. Is there any way to start it up but trick it into thinking I only have 1 CPU core?
It is not terminator
that is doing the "spreading" on all the CPU of a given process. Linux itself (the kernel) is doing this. A task (process) is scheduled as available to run on all CPUs by defaults; if it uses threads it can uses more than one CPU at a time.
To restrict a process to a specific CPU, you use the command taskset
.
taskset --cpu-list 1,2 my_command
This command forces my_command to run just on CPUs #1 or #2.
To learn more, type man taskset
or search for "linux CPU affinity" (first hit here).
Though another answer has already given the literal answer I would explore the possibility this is not being done the right way. Instead you should run a script which you do not want to slow down the computer (such as non interactive scripts) using the nice
command.
To do this simply prefix the command you wish to run with nice, for example:
nice command_to_run
This will cause the program to be de-prioritized below other tasks and will not slow down your machine. I often use this technique when doing a long compile which would otherwise slow down my PC to a crawl, this has the advantage of allowing the program to use all cores when the machine is not busy but will quickly stop it using them when you run something else.