On 9 February 2016, LCD 47 <[email protected]> wrote:
[...]
>     Starting a (presumably long-lived) server from Vim on the other hand
> is a very different animal.  A server might print things like error
> messages before it goes to background.  After that it isn't supposed
> to print anything or need output from stdin (doing that would rise a

    s/output/input/

> signal).  A server in background is supposed to communicate with other
> processes only though a socket (INET, or UNIX domain).

[...]
>     A further difference between long-lived and short-lived processes
> is the way process groups are handled.  For short-lived processes, the
> sequence should be something like this:
> 
> - fork()
> - in the child: exec()

    Better: close stdin, then exec().  Dealing with stdin while we're
also reading output can run into a deadlock.

> - in the parent: install a SIGCHLD and waitpid()
> 
>     For daemons the sequence should be:
> 
> - fork()
> - in the child: setsid(), fork() again, and exit

    Better yet: initialize, print errors etc., then setsid(), fork()
again, and exit.

> - in the second child: exec()

    Better: close fds 0-2, exec()

> - in the parent: blocking waitpid().
> 
>     To kill the group of a daemon, you need to kill() the negated PID
> of the _first_ child, because that's the session leader.
[...]

    "Mixed" modes are possible too, but we really don't want to go
there.

    /lcd

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

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

Raspunde prin e-mail lui