daemonのヘルプ・マニュアル
日本語 英語
daemon --help
man daemon
DAEMON(3) Linux Programmer’s Manual DAEMON(3)
名前
daemon - バックグラウンドで動作させる
書式
#include
int daemon(int nochdir, int noclose); glibc 向けの機能検査マクロの要件
(feature_test_macros(7) 参照):
説明
daemon() は、制御端末から分離させてシステムデーモンとして動作させたいプ
ログラムのための関数である。
引き数 nochdir が 0 の場合、 daemon() は現在の作業ディレクトリ (current
working directory) をルート ("/") に変更する。
引き数 noclose が 0 の場合、 daemon() は、標準入力・標準出力・標準エ ラ
ーを /dev/null にリダイレクトする。
返り値
( この関数が fork して fork(2) が成功すると、親プロセスでは _exit(2) を
呼び出すので、これ以降のエラーは子プロセスからしか見れない)。成功した場
合 は 0 を返す。エラーが起こった場合、 daemon() は -1 を返す。さらに、
errno に fork(2) と setsid(2) に関して規定されたエラーを設定する。
準拠
POSIX.1-2001 にはない。同様の関数が BSD には見られる。 daemon() 関数 は
4.4BSD で始めて登場した。
注意
/dev/null は存在するが、想定するメジャー番号とマイナー番号のキャラクタ
デバイスでなかった場合、 glibc の実装でも -1 が返される。こ の 場 合 、
errno が設定される必要はない。
関連項目
fork(2), setsid(2)
GNU 2009-02-23 DAEMON(3)
DAEMON(3) Linux Programmer’s Manual DAEMON(3)
NAME
daemon - run in the background
SYNOPSIS
#include
int daemon(int nochdir, int noclose);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
daemon(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
DESCRIPTION
The daemon() function is for programs wishing to detach themselves from
the controlling terminal and run in the background as system daemons.
If nochdir is zero, daemon() changes the process’s current working
directory to the root directory ("/"); otherwise,
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.
RETURN VALUE
(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 suc-
cess daemon() returns zero. If an error occurs, daemon() returns -1
and sets errno to any of the errors specified for the fork(2) and set-
sid(2).
CONFORMING TO
Not in POSIX.1-2001. A similar function appears on the BSDs. The dae-
mon() function first appeared in 4.4BSD.
NOTES
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.
SEE ALSO
fork(2), setsid(2)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2009-05-02 DAEMON(3)