1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on capability requirements
28 .\" 2008-05-03, mtk, expanded and rewrote parts of DESCRIPTION and RETURN
29 .\" VALUE, made style of page more consistent with man-pages style.
31 .TH GETGROUPS 2 2013-10-18 "Linux" "Linux Programmer's Manual"
33 getgroups, setgroups \- get/set list of supplementary group IDs
35 .B #include <sys/types.h>
37 .B #include <unistd.h>
39 .BI "int getgroups(int " size ", gid_t " list []);
43 .BI "int setgroups(size_t " size ", const gid_t *" list );
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
55 returns the supplementary group IDs of the calling process in
59 should be set to the maximum number of items that can be stored in the
62 If the calling process is a member of more than
64 supplementary groups, then an error results.
65 It is unspecified whether the effective group ID of the calling process
66 is included in the returned list.
67 (Thus, an application should also call
69 and add or remove the resulting value.)
75 is not modified, but the total number of supplementary group IDs for the
77 This allows the caller to determine the size of a dynamically allocated
79 to be used in a further call to
83 sets the supplementary group IDs for the calling process.
84 Appropriate privileges (Linux: the
86 capability) are required.
89 argument specifies the number of supplementary group IDs
90 in the buffer pointed to by
95 returns the number of supplementary group IDs.
96 On error, \-1 is returned, and
103 On error, \-1 is returned, and
105 is set appropriately.
110 has an invalid address.
113 can additionally fail with the following error:
117 is less than the number of supplementary group IDs, but is not zero.
120 can additionally fail with the following errors:
126 (32 before Linux 2.6.4; 65536 since Linux 2.6.4).
132 The calling process has insufficient privilege.
137 function is in POSIX.1-2001.
140 requires privilege, it is not covered by POSIX.1-2001.
142 A process can have up to
144 supplementary group IDs
145 in addition to the effective group ID.
150 The set of supplementary group IDs
151 is inherited from the parent process, and preserved across an
154 The maximum number of supplementary group IDs can be found at run time using
159 ngroups_max = sysconf(_SC_NGROUPS_MAX);
162 The maximum return value of
164 cannot be larger than one more than this value.
165 Since Linux 2.6.4, the maximum number of supplementary group IDs is also
166 exposed via the Linux-specific read-only file,
167 .IR /proc/sys/kernel/ngroups_max .
171 system call supported only 16-bit group IDs.
172 Subsequently, Linux 2.4 added
174 supporting 32-bit IDs.
177 wrapper function transparently deals with the variation across kernel versions.
181 .BR getgrouplist (3),
183 .BR capabilities (7),