/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that prints all the groupname the current
process belongs to. */
#include <stdio.h>
#include <unistd.h>
#define NGROUPS 100

int main() {
    int ngroups = NGROUPS;
    gid_t mygidset[NGROUPS];
    int ngrps;
    int i;

    setgroups(ngroups,mygidset); /* effect only for superuser */
    ngrps = getgroups (ngroups, mygidset);
    if(ngrps == -1) {
      perror(getgroups);
      exit(1);
    }
    else
    {
      for(i = 0; i<ngrps;i++){
        printf(" current process belongs to group %d\n",mygidset[i]);
      }
    }
}
