.\" Copyright Michael Haardt (michael@cantor.informatik.rwth-aachen.de) .\" Sat Aug 27 20:43:50 MET DST 1994 .\" and Copyright (C) 2014, Michael Kerrisk .\" .\" %%%LICENSE_START(GPLv2+_DOC_FULL) .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, see .\" . .\" %%%LICENSE_END .\" .\" Modified Sun Sep 11 19:19:05 1994 .\" Modified Mon Mar 25 10:19:00 1996 (merged a few .\" tiny changes from a man page by Charles Livingston). .\" Modified Sun Jul 21 14:45:46 1996 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated Sat Mar 1 16:46:43 JST 1997 .\" by HANATAKA Shinya .\" Modified Mon May 5 19:43:49 JST 1997 .\" by HANATAKA Shinya .\" Updated & Modified Thu Feb 10 22:45:24 JST 2005 .\" by Yuichi SATO .\" .TH SETSID 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 setsid \- セッション (session) を作成し、プロセスグループ ID を設定する .SH 書式 .ad l \fB#include \fP .br \fB#include \fP .PP \fBpid_t setsid(void);\fP .br .ad b .SH 説明 \fBsetsid\fP() は、 呼び出したプロセスがプロセスグループリーダー (process group leader) でなければ、 新しいセッションを作成する。 呼び出したプロセスは、 新しいセッションのリーダーとなる (すなわち、そのセッション ID がプロセス ID と同じ値になる)。 また、呼び出したプロセスは、 そのセッションの新しいプロセスグループのプロセスグループリーダーにもなる (すなわち、プロセスグループ ID がプロセス ID と同じ値になる)。 .PP 呼び出したプロセスは、 新しいプロセスグループと新しいセッションの唯一のプロセスとなる。 .PP 最初は、新しいセッションは制御端末を持たない。セッションが制御端末を獲得する方法については \fBcredentials\fP(7) を参照。 .SH 返り値 成功すると、呼び出したプロセスの (新しい) セッション ID が返される。 エラーの場合は、 \fI(pid_t)\ \-1\fP が返され、 \fIerrno\fP にエラーを示す値が設定される。 .SH エラー .TP \fBEPERM\fP いずれかのプロセスのプロセスグループ ID が、 呼び出したプロセスの PID と等しい。 これは、呼び出したプロセスが既にプロセスリーダーの場合には \fBsetsid\fP() は失敗することを意味する。 .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, SVr4. .SH 注意 \fBfork\fP(2) で作成された子プロセスは、親プロセスのセッション ID を継承する。 \fBexecve\fP(2) の前後でセッション ID は保存される。 .PP A process group leader is a process whose process group ID equals its PID. Disallowing a process group leader from calling \fBsetsid\fP() prevents the possibility that a process group leader places itself in a new session while other processes in the process group remain in the original session; such a scenario would break the strict two\-level hierarchy of sessions and process groups. In order to be sure that \fBsetsid\fP() will succeed, call \fBfork\fP(2) and have the parent \fB_exit\fP(2), while the child (which by definition can't be a process group leader) calls \fBsetsid\fP(). .PP セッションが制御端末を持っていて、その端末に対して \fBCLOCAL\fP フラグが設定されておらず、端末のハングアップが起きた場合、 セッションリーダーに \fBSIGHUP\fP シグナルが送られる。 .PP セッションリーダーのプロセスが終了した場合には、その制御端末のフォアグランドのプロセスグループに所属する各プロセスに \fBSIGHUP\fP シグナルが送られる。 .SH 関連項目 \fBsetsid\fP(1), \fBgetsid\fP(2), \fBsetpgid\fP(2), \fBsetpgrp\fP(2), \fBtcgetsid\fP(3), \fBcredentials\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。