get information about the group with a given name


#include <sys/types.h>
#include <grp.h>
struct group *getgrnam( const char *name );


The getgrnam() function allows a process to gain more knowledge about the group named name. This function uses a static buffer that is overwritten by each call.


A pointer to an object of type struct group containing an entry from the group database with a matching name. Upon error or failure to find an entry with a matching name, a NULL pointer is returned.


 * print the name of all users in the group given in 
 * argv[1]
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <grp.h>

void main( int argc, char **argv )
    struct group *g;
    char     **p;

    if( ( g = getgrnam( argv[1] ) ) == NULL ) {
       fprintf( stderr, "getgrnam: %s failed\n",
            argv[1] );
       exit( EXIT_FAILURE );
    printf( "group name:%s\n", g->gr_name );
    for( p = g->gr_mem; *p != NULL; p++ ) {
       printf( "\t%s\n", *p );
    exit( EXIT_SUCCESS );


POSIX 1003.1

Interrupt handler No
Signal handler No
Thread No

See also:

getgrent(), getgrgid()