1 .\" Copyright (C), 1994, Graeme W. Wilford. (Wilf.)
2 .\" and Copyright (C) 2010, 2015, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" Fri Jul 29th 12:56:44 BST 1994 Wilf. <G.Wilford@ee.surrey.ac.uk>
7 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
8 .\" Modified 2002-03-09 by aeb
10 .TH SETGID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
12 setgid \- set group identity
15 .RI ( libc ", " \-lc )
18 .B #include <unistd.h>
20 .BI "int setgid(gid_t " gid );
24 sets the effective group ID of the calling process.
25 If the calling process is privileged (more precisely: has the
27 capability in its user namespace),
28 the real GID and saved set-group-ID are also set.
32 is implemented like the POSIX version with the
35 This allows a set-group-ID program that is not set-user-ID-root
36 to drop all of its group
37 privileges, do some un-privileged work, and then reengage the original
38 effective group ID in a secure manner.
40 On success, zero is returned.
41 On error, \-1 is returned, and
43 is set to indicate the error.
47 The group ID specified in
49 is not valid in this user namespace.
52 The calling process is not privileged (does not have the
53 \fBCAP_SETGID\fP capability in its user namespace), and
55 does not match the real group ID or saved set-group-ID of
58 POSIX.1-2001, POSIX.1-2008, SVr4.
62 system call supported only 16-bit group IDs.
63 Subsequently, Linux 2.4 added
65 supporting 32-bit IDs.
68 wrapper function transparently deals with the variation across kernel versions.
70 .SS C library/kernel differences
71 At the kernel level, user IDs and group IDs are a per-thread attribute.
72 However, POSIX requires that all threads in a process
73 share the same credentials.
74 The NPTL threading implementation handles the POSIX requirements by
75 providing wrapper functions for
76 the various system calls that change process UIDs and GIDs.
77 These wrapper functions (including the one for
79 employ a signal-based technique to ensure
80 that when one thread changes credentials,
81 all of the other threads in the process also change their credentials.
90 .BR user_namespaces (7)