How does the scheduler find the primary group?

How does the scheduler find the primary group? I have a user (Adam) who is a member of multiple groups:
adama (primary group when using id to check group membership)
GroupA
GroupB

GroupC

….

GroupX

GroupY

GroupZ

We use newgrp to switch primary groups in the current session, this is due to the 16-group NFS limitation, and us needing to maintain per-group access control. For the sake of this question, this cannot be changed (i.e. no manage-gids, NFSv4, etc.)

So when Adam submits a job, his group in the session is GroupA, but when the job runs, it runs under adama. The workaround to set the group under which a job runs is -W group_list, but i wanted to see:

  1. If there’s another way to get PBS to respect the group at job submission time.
  2. Use a hook / wrapper to set -W group_list automatically

The discussion on this page might be helpful

Check this: getpwnam()

Hook and wrapper scripts are the way to go.