From: Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
To: Anders Peter Fugmann <anders@fugmann.net>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Bug when printing from signal handlers?
Date: Wed, 19 Mar 2014 23:19:11 +0100 [thread overview]
Message-ID: <CAGrdgiUoPC=Wa6cTkWyuhCSUhFw3D6+igcJ0CT0UEn9nHW1e3A@mail.gmail.com> (raw)
In-Reply-To: <532A0A5E.6070107@fugmann.net>
[-- Attachment #1: Type: text/plain, Size: 898 bytes --]
On Wed, Mar 19, 2014 at 10:21 PM, Anders Peter Fugmann
<anders@fugmann.net>wrote:
> Is printing from a signal handler illegal?
FWIW, that is illegal in some operating systems. I have seen it in one case
at least:
* Linux with threads. printf in C is protected by a mutex. Suppose we are
inside the printf, with the mutex locked and then we get a signal. We run
the handler, and it wants to print out debug information. Welcome deadlock!
* Many system calls are not safe in the signal handler. FreeBSD has a list
in sigaction(2) for instance. See
http://www.freebsd.org/cgi/man.cgi?query=sigaction&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html
In practice, you should probably just set a flag in the signal handler and
then handle that in a main loop of the program. Doing advanced stuff in a
signal handler is usually dangerous non-compatible territory.
--
J.
[-- Attachment #2: Type: text/html, Size: 1711 bytes --]
next prev parent reply other threads:[~2014-03-19 22:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 21:21 Anders Peter Fugmann
2014-03-19 22:19 ` Jesper Louis Andersen [this message]
2014-03-19 23:21 ` Gerd Stolpmann
2014-03-20 5:29 ` ygrek
2014-03-20 7:42 ` Anders Fugmann
2014-03-20 20:07 ` Gerd Stolpmann
2014-03-23 10:01 ` ygrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGrdgiUoPC=Wa6cTkWyuhCSUhFw3D6+igcJ0CT0UEn9nHW1e3A@mail.gmail.com' \
--to=jesper.louis.andersen@gmail.com \
--cc=anders@fugmann.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox