setgid

Section: System Calls (2)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

setgid - グループ識別(identity)を設定する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <unistd.h>

int setgid(gid_t gid);
 

説明

setgid() sets the effective group ID of the calling process. If the calling process is privileged (more precisely: has the CAP_SETGID capability in its user namespace), the real GID and saved set-group-ID are also set.

Linux において、 setgid() は _POSIX_SAVED_IDS をもった POSIX 版のように実装されている。 これは set-user-ID-root でない set-group-ID プログラムにそのグループの 特権の全て落とし、特権の必要ない仕事をし、本来の実効グループID に 安全な方法で再び戻すことを許す。  

返り値

On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error.  

エラー

EINVAL
gid で指定されたグループ ID がこのユーザー名前空間では有効ではない。
EPERM
呼び出し元のプロセスに権限がなく (そのプロセスのユーザー名前空間で CAP_SETGID ケーパビリティがなく)、かつ gid が呼び出し元のプロセスの実グループID と保存セットグループID のどちらとも一致しない。
 

バージョン

 

C ライブラリとカーネルの違い

At the kernel level, user IDs and group IDs are a per-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for setgid()) employ a signal-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see nptl(7).  

標準規格

POSIX.1-2024.  

歴史

POSIX.1-2001, SVr4.

元々の Linux の setgid() システムコールは 16 ビットのグループ ID だけに対応していた。 その後、Linux 2.4 で、32 ビットの ID に対応した setgid32() が追加された。 glibc の setgid() のラッパー関数は カーネルバージョンによるこの違いを吸収している。  

関連項目

getgid(2), setegid(2), setregid(2), capabilities(7), credentials(7), user_namespaces(7)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
バージョン
C ライブラリとカーネルの違い
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.