On Tue, 18 May 2021 21:40:15 +0000, Alexander Grotewohl via fpc-pascal <fpc-pascal@lists.freepascal.org> wrote:
>if it's waiting on keyboard input you might be better off using select() for >that instead of looping and checking for keyboard input each go around. > >sleep() might already do something similar with a zero timeout but even that >would probably be insufficient As I tried to explain at the start of this thread my application runs as a *systemd service* on Linux, so there is absolutely no keyboard input. The main program looks like this after initializations etc: try try bSTerm := False; bSInt := False; bsHup := False; {$IFDEF UNIX} fpSignal(SigTerm, SignalHandler(@handleSignal)); fpSignal(SigInt, SignalHandler(@handleSignal)); fpSignal(SigHup, SignalHandler(@handleSignal)); {$ENDIF} Debug_Writeln('Enter eternal loop'); FLogServ.StdLog('Enter eternal loop'); While not (bSTerm or bSInt or bsHup) do begin //Here is where the server runs as defined elsewhere //Eternal loop to wait for system messages Sleep(1); //To not hog the CPU CheckSynchronize; //To get thread comm working end; Debug_Writeln('Exit eternal loop'); FLogServ.StdLog('Exit eternal loop'); except on E: Exception do begin FLogServ.ExceptionLog('Unhandled exception: ' + E.Message); end; end; finally ShutdownServer; end; As you can see it sits in the eternal loop until the system sends a "signal" to it to stop. So systemd does that if I issue a sudo systemctl stop myservice and this works fine. Could this tiny loop consume 6-7% CPU cycles? -- Bo Berglund Developer in Sweden _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal