We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Finding group id from PID

jjrrww asked
Medium Priority
Last Modified: 2013-12-20
I'm trying to determine a list of process ids that are associated with a particular group (i.e., the owner of the process belongs to the group) That is, if I look at a PID, I can determine the UID.  I then want to know if that UID is in a particular group.

As best I can tell I have to:
- get the UID from the PID using getprocs64
- get the username from the UID using getpwuid(uid)

then, given the groupname I need to call getgrnam(groupName)
which will give me a group structure.  grp->gr_mem is then an array of strings, which Il will have to parse looking for the username.

Then I have to repeat that for every process in the system.

Surely there is a less pedestrian way.
Watch Question


Rather than explain what I'm trying to do... this is what I am trying to accomplish:

Given the set of processes currently running on the system, I need to identify those processes (pids) which belong to a group.  My application allows a user to collect metrics about a subset of processes.  That subset is defined by one or more of several criteria:

username (which maps to UID, which is readily gleaned from the process)
group (the problem at hand)
command (the program being run)
or matching a token on the command line.

Except for group, all are readily available on the procsinfo64 structure returned by getprocs64.

It would appear that I have to go on a scavenger hunt to identify the processes that are "in" a particular group.

Is there a better way that I'm missing?
I can't see a better way - I can't see any gid anywhere in /usr/include/sys/proc.h. Did you try at http://www.ibm.com/developerworks/?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

This sounds like something a "ps" command can get you.

On AIX,  try "ps -aef" will get you all that and pipe it to a "grep" command to select your specific need.


I guess the final understanding of this is that a group is not in any way a process attribute, but rather a username attribute, with a many-many realtionship.  As a result, chasing after those relationships is the only way to do it.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.