0

I have a process that is mining a private blockchain and it takes 100% of the CPU. I don't need that much computing power for this, so in order to reduce my energy bill I need to configure this particular process to be scheduled only once in a while to achieve around 10% consumption of the CPU.

How do I reduce the timeslice that a particular process is getting ?

1

You can try to use tools like cpulimit (normally should be available in repos of popular distros). It allows to limit the CPU usage by percentage, which might be more convenient.

Otherwise you might want to control it via cgroups-tools and set the limit with cgcreate / cgset. You need to adjust values cpu.cfs_period_us and cpu.cfs_quota_us.

  • haha! 1340 lines of C code just to send SIGKILL and SIGCONT periodically, wow! That must be some college student exam or some sort of assignment at school. Check my answer to this question to find out how it is done with 14 lines of bash scripting – Nulik Jun 6 at 20:43
  • @Nulik it's not a code golf challenge. Most of the C code is exception handling and various user-friendly messages. – rush Jun 7 at 11:44
0
#!/bin/bash
#reduces consumption to 10% CPU using `sleep`s
GETH_PID=$1
if [ "$GETH_PID" == "" ] ; then
    echo usage $0 GETH_PID
    exit
fi
while true
do
    kill -STOP $GETH_PID
    sleep 9
    kill -CONT $GETH_PID
    sleep 1
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.