public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* call a function even a program terminate abnormally
@ 2017-08-05  8:13 Yubin Ruan
  2017-08-05  9:29 ` Patrick Schlangen
  0 siblings, 1 reply; 4+ messages in thread
From: Yubin Ruan @ 2017-08-05  8:13 UTC (permalink / raw)
  To: libc-help

Hi,
I am wondering whether it is possible to invoke a function when a program
terminate abnormally (e.g., segfault). I know "atexit(3)" will do the job
if the process terminate normally. But I am wondering whether that is possible
for the abnormal case. Any system call for this (on Linux)?

I am doing some interprocess communication here. If a process just die with
a lock unlocked, there might be potential deadlock.

Thanks,
Yubin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: call a function even a program terminate abnormally
  2017-08-05  8:13 call a function even a program terminate abnormally Yubin Ruan
@ 2017-08-05  9:29 ` Patrick Schlangen
  2017-08-05  9:31   ` Marcin Mielniczuk
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Schlangen @ 2017-08-05  9:29 UTC (permalink / raw)
  To: Yubin Ruan; +Cc: libc-help

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: call a function even a program terminate abnormally
  2017-08-05  9:29 ` Patrick Schlangen
@ 2017-08-05  9:31   ` Marcin Mielniczuk
  2017-08-05  9:47     ` Patrick Schlangen
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Mielniczuk @ 2017-08-05  9:31 UTC (permalink / raw)
  To: Patrick Schlangen, Yubin Ruan; +Cc: libc-help

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: call a function even a program terminate abnormally
  2017-08-05  9:31   ` Marcin Mielniczuk
@ 2017-08-05  9:47     ` Patrick Schlangen
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick Schlangen @ 2017-08-05  9:47 UTC (permalink / raw)
  To: Marcin Mielniczuk; +Cc: Yubin Ruan, libc-help

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.
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-05  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-05  8:13 call a function even a program terminate abnormally Yubin Ruan
2017-08-05  9:29 ` Patrick Schlangen
2017-08-05  9:31   ` Marcin Mielniczuk
2017-08-05  9:47     ` Patrick Schlangen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).