« Reply #5 on: April 03, 2025, 02:05:55 pm »
Thanks.
I also asked this from AI and got this example:
program GracefulShutdownExample;
uses
SysUtils, Classes, Signal;
procedure HandleSignal(Sender: TObject);
begin
Writeln('Received termination signal. Shutting down gracefully...');
// Perform cleanup tasks here
// For example, save data, close files, release resources, etc.
// Exit the application
Halt;
end;
var
SignalHandler: TSignalHandler;
begin
// Create a signal handler for SIGTERM and SIGINT
SignalHandler := TSignalHandler.Create(nil);
try
SignalHandler.Signals := [sigTERM, sigINT];
SignalHandler.OnSignal := HandleSignal;
Writeln('Application is running. Press Ctrl+C to terminate.');
// Simulate application running
while True do
begin
Sleep(1000);
end;
finally
SignalHandler.Free;
end;
end.
Now I don't know where is the unit Signal?
I got reply:
The Signal unit in Free Pascal/Lazarus is part of the Free Pascal RTL (Run-Time Library) and is designed to provide signal handling capabilities. The unit is located in the rtl/win32 directory for Windows, and it aims to offer similar signal handling functionalities across different platforms[..]
Maybe because the unit-name is in fact "signal
s"...
On my machine at:
C:\lazarus\fpc\3.2.2\source\rtl\win32
{
This file is part of the Free Pascal run time library.
This unit implements unix like signal handling for win32
Copyright (c) 1999-2006 by the Free Pascal development team.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit signals;
interface
{$PACKRECORDS C}
{ Signals }
const
SIGABRT = 288;
SIGFPE = 289;
SIGILL = 290;
SIGSEGV = 291;
SIGTERM = 292;
SIGALRM = 293;
SIGHUP = 294;
SIGINT = 295;
SIGKILL = 296;
SIGPIPE = 297;
SIGQUIT = 298;
SIGUSR1 = 299;
SIGUSR2 = 300;
SIGNOFP = 301;
SIGTRAP = 302;
SIGTIMR = 303; { Internal for setitimer (SIGALRM, SIGPROF) }
SIGPROF = 304;
SIGMAX = 320;
SIG_BLOCK = 1;
SIG_SETMASK = 2;
SIG_UNBLOCK = 3;
function SIG_DFL( x: longint) : longint; cdecl;
function SIG_ERR( x: longint) : longint; cdecl;
function SIG_IGN( x: longint) : longint; cdecl;
type
SignalHandler = function (v : longint) : longint;cdecl;
PSignalHandler = ^SignalHandler; { to be compatible with linux.pp }
function signal(sig : longint;func : SignalHandler) : SignalHandler;
const
EXCEPTION_MAXIMUM_PARAMETERS = 15;
type
//and so on....
« Last Edit: April 03, 2025, 02:07:27 pm by Zvoni »

Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad