Reputation: 9512
I wonder if it is possible having N cores on production server tall gcc that I want it to use 50% of each core while compiling/linking? Can we start gcc from some other application that would allow it to use only half of cpu?
Upvotes: 0
Views: 153
Reputation: 176
gcc, like most programs, has no built-in way to slow itself down. You could write a wrapper program that spawns a subprocess, and then repeatedly uses the POSIX functions usleep
and kill
in a loop to stop and restart it until it finishes. However, I am wondering why you need to use each core 50% of the time, rather than using half of the cores 100% of the time -- which, as has already been pointed out, is far easier to accomplish by adjusting the number of parallel jobs make
runs. For example, make -j 2
will limit the number of gcc
processes to 2.
Edit: You may also be able to achieve your goal by running make
with a high niceness level.
Upvotes: 1