From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL,MISSING_HEADERS autolearn=disabled version=3.1.3 X-Original-To: Caml-list@yquem.inria.fr Delivered-To: Caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id CD86BBBCA for ; Fri, 15 Feb 2008 09:18:46 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIbZtEdYVljmh2dsb2JhbACBWY5yAQEBCAopngc X-IronPort-AV: E=Sophos;i="4.25,357,1199660400"; d="scan'208";a="7343135" Received: from orel-uisistem.88.quantum.ru (HELO office.stork.ru) ([88.86.88.230]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Feb 2008 09:18:46 +0100 Received: from serp.office.stork.ru (serp [192.168.21.130]) by office.stork.ru (8.13.5/8.13.5) with ESMTP id m1F9daRn032143 for ; Fri, 15 Feb 2008 12:39:36 +0300 Message-ID: <47B54AE4.6090803@stork.ru> Date: Fri, 15 Feb 2008 11:18:44 +0300 From: SerP User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 Cc: Caml-list@yquem.inria.fr Subject: Re: [Caml-list] Threads, Signals and Events References: <20080215091910.bb982431.mle+ocaml@mega-nerd.com> In-Reply-To: <20080215091910.bb982431.mle+ocaml@mega-nerd.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; syslog:01 syslog:01 sigterm:01 mli:01 cheers:01 forks:01 threads:01 threads:01 wrote:01 caml-list:01 writes:01 behaviour:01 kernel:02 btw:03 seems:03 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.