This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: call a function even a program terminate abnormally
- From: Patrick Schlangen <patrick at schlangen dot me>
- To: Marcin Mielniczuk <marmistrz dot dev at zoho dot eu>
- Cc: Yubin Ruan <ablacktshirt at gmail dot com>, libc-help at sourceware dot org
- Date: Sat, 5 Aug 2017 11:47:17 +0200
- Subject: Re: call a function even a program terminate abnormally
- Authentication-results: sourceware.org; auth=none
- References: <CAJYFCiMvufz7LK6jQdwubqC520pQLV1=vHiekkOVfL1mLXDd5Q@mail.gmail.com> <5c66ce10bb773a99814413559663ba16@mail.b1g.net> <69AFB44B-9A85-42FE-A7BB-9AA39863021D@zoho.eu>
Be aware that SIGKILL cannot be caught...
Another idea would be to have a monitoring process which spawns your program, monitors it and does cleanup once it dies.
Patrick
Von meinem iPhone gesendet
> Am 05.08.2017 um 11:31 schrieb Marcin Mielniczuk <marmistrz.dev@zoho.eu>:
>
> I guess you'd have to install handlers for every possible signal. Your program can receive SIGTERM, SIGKILL, ...
>
>> On August 5, 2017 11:29:51 AM GMT+02:00, Patrick Schlangen <patrick@schlangen.me> wrote:
>> Hi Yubin,
>>
>>> I am wondering whether it is possible to invoke a function when a
>> program
>>> terminate abnormally (e.g., segfault).
>>
>> you could install a signal handler for SIGSEGV using signal() (2),
>> but please be aware of all the pitfalls.
>>
>> When your process receives SIGSEGV, you probably have some
>> memory corruption ongoing and you don't know if the data structure
>> holding your lock is still valid.
>>
>> Best Regards,
>>
>> Patrick
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>
>