From: SerP <serp@stork.ru>
Cc: Caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Threads, Signals and Events
Date: Fri, 15 Feb 2008 11:18:44 +0300 [thread overview]
Message-ID: <47B54AE4.6090803@stork.ru> (raw)
In-Reply-To: <20080215091910.bb982431.mle+ocaml@mega-nerd.com>
Erik de Castro Lopo wrote:
> Hi all,
>
> I'm doing some systems programming where I need to use threads
> (standard threads, not cothreads), signals and events. The program
> has a couple of things to do:
>
> a) Start program X, do a wait on its pid and restart X if it dies
> and log information to syslog.
> b) Periodically run other system checks and log results to syslog.
> Certain types of system failures need to be communicated to
> program X so that it can modify its behaviour.
> c) Catch SIGHUP, and on reception, kill program X (send SIGHUP first
> and if that doesn't work SIGTERM and finally SIGKILL) and then
> exit itself.
>
> Since the system checks can take some time (mostly waiting for the
> kernel to do stuff rather than intensive processing) and program X
> needs to be restarted immediately if it dies, using threads seems
> to be an obvious solution.
>
> However, reading between the lines of thread.mli suggests that
> signals should be blocked on all threads but one which catches
> signals using Thread.wait_signal and then sends events using the
> Event module to the other threads.
>
> This makes for four threads:
>
> - Main thread which waits for SIGHUP and sends an Event when it
> does.
> - Monitor thread which waits for program X to exit using
> Thread.wait_pid.
> - A syscheck thread which pretty much does its thing and log its
> results by sending an Event to the logger thread.
> - Logger thread which receives events from the other threads and
> writes to syslog.
>
> The problem with the above is that the monitor thread needs to wait
> on both a pid and an Event and I can't see any way to do that.
>
> Anybody have any suggestions? This is on Linux btw.
>
> Cheers,
> Erik
>
Forks is more suitable for this task.
prev parent reply other threads:[~2008-02-15 8:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-14 22:19 Erik de Castro Lopo
2008-02-15 6:47 ` [Caml-list] " Christophe Raffalli
2008-02-15 8:18 ` SerP [this message]
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=47B54AE4.6090803@stork.ru \
--to=serp@stork.ru \
--cc=Caml-list@yquem.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