getgroups() 函数原型如下:
[C++] 纯文本查看 复制代码 #include <sys/types.h>
#include <unistd.h>
int getgroups(int size, gid_t list[]);
getgroups() 函数用来获取当前用户所属组的组ID(GID) 。函数有两个参数,list[] 是个 gid_t 数组,它用来存储 GID ,size 表示 list[] 所能存储的 gid_t 数目。如果 size 为 0,那么 list[] 不会被修改,函数就只返回用户属组的数目。
测试代码:
[C++] 纯文本查看 复制代码 #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
gid_t list[8];
int x, i;
x = getgroups(8, list);
for (i = 0; i < x; i++)
printf ("%d : %d\n", i, list[i]);
return 0;
}
运行输出:./getgroups
0 : 33
1 : 100 |