.\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)daemon.3 8.1 (Berkeley) 6/9/93 .\" Added mentioning of glibc weirdness wrt unistd.h. 5/11/98, Al Viro .\" .\" Japanese Version Copyright (c) 2000-2001 Yuichi SATO .\" all rights reserved. .\" Translated Tue Jun 27 10:54:22 JST 2000 .\" by Yuichi SATO .\" Updated & Modified Mon Jan 14 06:50:04 JST 2002 .\" by Yuichi SATO .\" .\"WORD: detach 分離 .\"WORD: controlling terminal 制御端末 .\"WORD: current working directory カレント・ワーキング・ディレクトリ .\"WORD: global variable 大域変数 .\" .TH DAEMON 3 2009-12-05 "GNU" "Linux Programmer's Manual" .SH 名前 daemon \- バックグラウンドで動作させる .SH 書式 .B #include .sp .BI "int daemon(int " nochdir ", int " noclose ); glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .SH 説明 .BR daemon () は、制御端末から分離させてシステムデーモンとして動作させたい プログラムのための関数である。 .PP .I nochdir が 0 の場合、 .BR daemon () は呼び出したプロセスの現在の作業ディレクトリ (current working directory) をルートディレクトリ ("/") に変更する。 それ以外の場合、現在の作業ディレクトリは変更されない。 .PP .I noclose が 0 の場合、 .BR daemon () は標準入力・標準出力・標準エラーを \fI/dev/null\fP にリダイレクトする。 それ以外の場合、これらのファイル・ディスクリプタは変更されない。 .SH 返り値 (この関数が fork して .BR fork (2) が成功すると、親プロセスでは .BR _exit (2) を呼び出すので、これ以降のエラーは子プロセスからしか見れない)。 .\" アンダースコア _ に下線を引かないようにするため .IR は使わない。 成功した場合、 .BR daemon () は 0 を返す。 エラーが起こった場合、 .BR daemon () は \-1 を返す。 さらに、 .I errno に .BR fork (2) と .BR setsid (2) に関して規定されたエラーを設定する。 .SH 準拠 POSIX.1-2001 にはない。 同様の関数が BSD には見られる。 .BR daemon () 関数は 4.4BSD で始めて登場した。 .SH 注意 .I /dev/null は存在するが、想定するメジャー番号とマイナー番号の キャラクタデバイスでなかった場合、 glibc の実装でも \-1 が返される。 この場合、 .I errno が設定される必要はない。 .SH 関連項目 .BR fork (2), .BR setsid (2)