Sending a function to background in Async

19 views
Skip to first unread message

Paolo Donadeo

unread,
Aug 23, 2014, 7:06:16 PM8/23/14
to Core mailing list
When writing a daemon, using the standard Unix module, I usually send the "main" function to background using the classical double-fork technique:

match fork () with
| 0 -> if fork () <> 0 then exit 0;
      (* do whatever the child should do *)
| _ -> wait ();
      (* do whatever the parent should do *)

(source code stolen from Unix system programming in OCaml)

In Async of course this don't work. How can I achieve the same result?

BTW, I'm still writing in the Core mailing list about Async, is it ok?


--
Paolo

Malcolm Matalka

unread,
Aug 23, 2014, 7:21:14 PM8/23/14
to ocaml...@googlegroups.com
I believe Async or Core comes with a daemonize module you can use to
accomplish this.

Alternatively you can do your forking and everything before running the
scheduler, so old school rules apply there.

And I think 'Core' referrers to the 'Core Suite', of which Async is a
member.

Paolo Donadeo <p.do...@gmail.com> writes:

> When writing a daemon, using the standard Unix module, I usually send the
> "main" function to background using the classical double-fork technique:
>
> *match fork () with*
> *| 0 -> if fork () <> 0 then exit 0;*
> * (* do whatever the child should do *)*
> *| _ -> wait ();*
> * (* do whatever the parent should do *)*
>
> *(source code stolen from *Unix system programming in OCaml
> <http://ocamlunix.forge.ocamlcore.org/processes.html>*)*
>
> In Async of course this don't work. How can I achieve the same result?
>
> BTW, I'm still writing in the Core mailing list about Async, is it ok?
>
>
> --
> *Paolo*

David House

unread,
Aug 24, 2014, 5:23:01 AM8/24/14
to ocaml...@googlegroups.com

Indeed, you should use Core.Std.Daemon.daemonize. Incidentally, this module is in core and not async because you must do this before starting the async scheduler.

--
You received this message because you are subscribed to the Google Groups "ocaml-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo Donadeo

unread,
Aug 24, 2014, 9:24:19 AM8/24/14
to Core mailing list
Thanks!


--
Paolo
Reply all
Reply to author
Forward
0 new messages