[Lazarus] Finding out how a program's being terminated

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Feb 16 14:30:09 CET 2013


Mark Morgan Lloyd schrieb:
> Sven Barth wrote:
>> On 16.02.2013 09:22, Mark Morgan Lloyd wrote:
>>> On unix (Linux, Solaris etc.) is it possible to determine how a program
>>> written using Lazarus is being terminated? Specifically, is there any
>>> different behaviour when a  kill  signal arrives from a routine  term
>>> signal, and is a title-bar close button simply a  term  signal?
>>
>> SIGTERM can be caught and handled by application using a signal 
>> handler, so it can do some cleanup or even ignore the signal completely.
>> SIGKILL can not be caught and will directly kill the process without 
>> any chance for further progressing.
>>
>> And a title bar close button does normally invoke a event of the used 
>> GUI toolkit (in case of Windows it would be the message "WM_CLOSE", I 
>> don't know the event names of GTK and Qt :) ) and not send a SIGTERM.

The handling of the close button, menu entry etc. GUI element IMO can be 
unified into a CloseQuery, possibly followed by a Close - provided that 
the program/library can determine that it is the result of a GUI action, 
affecting only a specific instance.


> So I think this leaves two cautionary cases which arise because a term 
> signal can be sent to multiple programs simultaneously (e.g. by the 
> killall5 program). The first is that a shutdown caused by a term signal 
> should not attempt to e.g. save state to a .ini file if there's a risk 
> that that file is shared without waiting for manual confirmation. The 
> second is that if a shutdown presents a dialogue box this should not 
> have a user-friendly "I'll save your data after five seconds" default, 
> unless it's absolutely certain that the files won't be shared (this 
> might be acceptable for a WM close event, but definitely not for a signal).

Compromise: try saving all data, skipping write-locked files.

I'm not sure how to deal with unsaved data in general. A program can ask 
"Sure to exit?" first, then determine whether unsaved data exist, ask 
"Exit without saving?", before really terminating. But it also can 
decide to exit immediately, if no data deserve saving, or to save before 
asking "Sure to exit?".

Procedures even may be different for Linux and Windows, depending on the 
signal/message types. Even if a program can ignore SIGTERM, can it also 
inform the system that it doesn't *want* to close? On Windows a program 
can stop an shutdown, maybe not on other platforms.

DoDi





More information about the Lazarus mailing list