End of Life Ruby 3.0 has reached end of life and gets no more fixes. 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;
}
Get an Array of the group IDs in the supplemental group access list for this process.
Example
Process.groups #=> [27, 6, 10, 11]
Note that this method is just a wrapper of getgroups(2). This means that the following characteristics of the result completely depend on your system:
-
the result is sorted
-
the result includes effective GIDs
-
the result does not include duplicated GIDs
You can make sure to get a sorted unique GID list of the current process by this expression:
Example
Process.groups.uniq.sort