libev: notify only one process when multiple processes are listening socket

Marc Lehmann schmorp at schmorp.de
Wed Jul 17 08:34:15 CEST 2013


On Tue, Jul 16, 2013 at 11:35:33AM -0700, trafdev <trafdev at mail.ru> wrote:
> I don't want to introduce threads or IPC mechanisms.

You simply have to, unless you can use an OS specific mechanism to do it
for you.

(examples would be: send a token around, have a reverse proxy distribute
the conenctions etc.).

>    int wrk = thread::hardware_concurrency();
>    while (--wrk) {
>        pid_t pid = fork();
>        if (pid == 0) {
>            ev::default_loop().post_fork();
>            ev::default_loop().run();
>            return true;
>        }
>    }
>    ev::default_loop().run();
>    return true;

This works - make sure you don't start any watchers before fork, unless
you want those watchers to be active in all children.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list