I'm writing a simple application in C to handle switching relays on an old Pi 1B. When the Pi is supposed to wait for the next action to handle, I use the sleep()
system call. I checked with top
, only to find out that my application still uses 10% CPU! Why?? So I tried to rewrite the code using alarm()
and pause()
. Of course the same: 10% CPU. Again: why??
Is there a way to put the process really to sleep, 0% CPU? Tips maybe?
Proof of a simple application using 10%:
#include <json-c/json.h>
#include <json-c/json_util.h>
main() {
gpioInitialise();
sleep(10000);
}
sleep
pauses execution of a process, but the original process may have spawned other processes, and these child processes won't necessarily pause. You may have to pause at the "kernel level" to reach your objective; here's a paper discussing some ways to do that