transmit group set to a child under SUN Solaris

SUN Solaris 'exec' system call reset the current group set.

Does anybody know aworkaround for this?

the following chunk of code well explain the problem: the child process does not inherit the additional group. Under Linux and AIX it does, that is the code below works fine.

  if ((ngroups=getgroups(NGROUPS_MAX,array_of_gids))==-1){
    if (!silent)
      perror("ERROR! getgroups");
    return 10;

  /* Add a group to array of groups */
  array_of_gids[ngroups++]= <any group number you like>;
  if (setgroups(ngroups,array_of_gids)==-1){
    if (!silent)
      perror("ERROR! setgroups");
    return 2;


thank you all
Who is Participating?
ecwConnect With a Mentor Commented:
Yep, I've checked it, and the man page for groups(1).  If you replace system("groups") with system("id -a") you might find it is in fact working.  groups(1) gets its info from /etc/passwd and /etc/group, not the current process context.
err, are you running as non-root with silent != 0
mliberiAuthor Commented:
the chunk of code I submitted runs with effective user id ==0

silent is a flag used to optionally disable printing error messages to stderr. You can assume it to be FALSE.

The program executes the last command 'system("groups")', but the group previously added doesn't appear in the output generated by 'groups' command.
mliberiAuthor Commented:

I'm glad to discover that my problem was so simple to solve.
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.