Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Process.groups
Process.groups → array
process.c
View on GitHub ↗
static VALUE
proc_getgroups(VALUE obj)
{
VALUE ary, tmp;
int i, ngroups;
rb_gid_t *groups;
ngroups = getgroups(0, NULL);
if (ngroups == -1)
rb_sys_fail(0);
groups = ALLOCV_N(rb_gid_t, tmp, ngroups);
ngroups = getgroups(ngroups, groups);
if (ngroups == -1)
rb_sys_fail(0);
ary = rb_ary_new();
for (i = 0; i < ngroups; i++)
rb_ary_push(ary, GIDT2NUM(groups[i]));
ALLOCV_END(tmp);
return ary;
}
Returns an array of the group IDs in the supplemental group access list for the current process:
Example
Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000]
These properties of the returned array are system-dependent:
-
Whether (and how) the array is sorted.
-
Whether the array includes effective group IDs.
-
Whether the array includes duplicate group IDs.
-
Whether the array size exceeds the value of
Process.maxgroups.
Use this call to get a sorted and unique array:
Example
Process.groups.uniq.sort