[Haskell-cafe] How to daemonize a threaded Haskell program?
Bas van Dijk
v.dijk.bas at gmail.com
Sat Mar 5 23:59:03 CET 2011
On 5 March 2011 21:51, Vincent Hanquez <tab at snarc.org> wrote:
> On Sat, Mar 05, 2011 at 08:51:59PM +0100, Bas van Dijk wrote:
>> Hello,
>>
>> I like to turn my Haskell program into a unix daemon. One of the steps
>> in "daemonizing" a process is to fork it then exit the parent and
>> continue with the child. All this is nicely abstracted in
>> hdaemonize[1] which internally calls forkProcess[2].
>>
>> I would also like to use multiple simultaneous threads in my program.
>> Unfortunately forkProcess is not supported when running with +RTS -N
>> so I can't use hdaemonize.
>>
>> I understand why it's problematic to fork a process which is in the
>> middle of running multiple simultaneous threads. However, in the case
>> of a daemon the fork happens in the beginning of the program. So if I
>> can manage to create a program that first daemonizes my process then
>> starts the Haskell program, all is good.
>>
>> My current plan is to have a custom Haskell main function which is
>> exported using the FFI:
>
> Hi,
>
> Did you alternatively though about daemonizing in your haskell program normally
> without using +RTS -N, and exec'ing yourself (using executeFile) with the extra
> cmdline +RTS -N options, and also --no-daemon option to avoid re-daemon/exec'ing ?
>
> I think that would be simpler than your current approch.
What a nice idea! I actually looked for a unix command line tool that
could do this but did not think further about doing it myself.
Thanks,
Bas
P.S.
So is there a tool that daemonizes another program? Sounds like a job
for a neat little Haskell program...
More information about the Haskell-Cafe
mailing list