From b473bdd8b0bf6f73a4267a5dc1e6ba2a2d225363 Mon Sep 17 00:00:00 2001 From: longxiaozhang Date: Thu, 30 Nov 2023 17:00:37 +0800 Subject: [PATCH] Update cpulimit.c fix bug: avoid cpulimit eats up too much cpu resource --- src/cpulimit.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cpulimit.c b/src/cpulimit.c index 50eabeac..c6ca3d7f 100644 --- a/src/cpulimit.c +++ b/src/cpulimit.c @@ -242,10 +242,15 @@ void limit_process(pid_t pid, double limit, int include_children) } //adjust work and sleep time slices + if (workingrate < 0) { + workingrate = limit; + } if (pcpu < 0) { //it's the 1st cycle, initialize workingrate pcpu = limit; - workingrate = limit; + twork.tv_nsec = TIME_SLOT * limit * 1000; + } + if (pcpu == 0) { twork.tv_nsec = TIME_SLOT * limit * 1000; } else {