Scroll to navigation

daemon(3) Library Functions Manual daemon(3)

NOME

daemon - rodar no background

BIBLIOTECA

Biblioteca C Padrão (libc, -lc)

SINOPSE

#include <unistd.h>
int daemon(int nochdir, int noclose);

Requisitos de macro de teste de recursos para o glibc (consulte feature_test_macros(7)):

daemon():


Desde o glibc 2.21:
_DEFAULT_SOURCE
No glibc 2.19 e 2.20:
_DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
Até e incluindo o glibc 2.19:
_BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)

DESCRIÇÃO

A função daemon() serve para desvincular o programa do terminal controlador e fazê-lo rodar no background como um daemon.

If nochdir is zero, daemon() changes the process's current working directory to the root directory ("/"); otherwise, the current working directory is left unchanged.

If noclose is zero, daemon() redirects standard input, standard output, and standard error to /dev/null; otherwise, no changes are made to these file descriptors.

VALOR DE RETORNO

(This function forks, and if the fork(2) succeeds, the parent calls _exit(2), so that further errors are seen by the child only.) On success daemon() returns zero. If an error occurs, daemon() returns -1 and sets errno to any of the errors specified for the fork(2) and setsid(2).

ATRIBUTOS

Para uma explicação dos termos usados nesta seção, consulte attributes(7).

Interface Atributo Valor
daemon() Thread safety MT-Safe

PADRÕES

Not in POSIX.1. A similar function appears on the BSDs. The daemon() function first appeared in 4.4BSD.

NOTAS

The glibc implementation can also return -1 when /dev/null exists but is not a character device with the expected major and minor numbers. In this case, errno need not be set.

BUGS

The GNU C library implementation of this function was taken from BSD, and does not employ the double-fork technique (i.e., fork(2), setsid(2), fork(2)) that is necessary to ensure that the resulting daemon process is not a session leader. Instead, the resulting daemon is a session leader. On systems that follow System V semantics (e.g., Linux), this means that if the daemon opens a terminal that is not already a controlling terminal for another session, then that terminal will inadvertently become the controlling terminal for the daemon.

VEJA TAMBÉM

fork(2), setsid(2), daemon(7), logrotate(8)

TRADUÇÃO

A tradução para português brasileiro desta página man foi criada por Paulo César Mendes <drpc@ism.com.br> e André Luiz Fassone <lonely_wolf@ig.com.br>

Esta tradução é uma documentação livre; leia a Licença Pública Geral GNU Versão 3 ou posterior para as condições de direitos autorais. Nenhuma responsabilidade é aceita.

Se você encontrar algum erro na tradução desta página de manual, envie um e-mail para a lista de discussão de tradutores.

15 dezembro 2022 Linux man-pages 6.03