#include #include #include #include #include #include #include #include #include #include static bool want_continue = true; void stop_me(int sig) { want_continue = false; } void *call_getpwuid(void *arg) { struct passwd pwd; char buf[8192]; struct passwd *res; while (want_continue) { getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &res); } return NULL; } void *call_getgrgid(void *arg) { struct group grp; char buf[8192]; struct group *res; while (want_continue) { getgrgid_r(getgid(), &grp, buf, sizeof(buf), &res); } return NULL; } int main(int argc, char **argv) { int i; int thread_count; pthread_t *threads; void *(*start_routine) (void *); if (argc != 3) { fprintf(stderr, "usage: ./prog UID|GID \n"); return 1; } if (strcmp(argv[1], "UID") == 0) { start_routine = call_getpwuid; } else if (strcmp(argv[1], "GID") == 0) { start_routine = call_getgrgid; } else { fprintf(stderr, "usage: ./prog UID|GID \n"); return 2; } signal(SIGINT, stop_me); thread_count = atoi(argv[2]); threads = (pthread_t *) calloc(sizeof(pthread_t), thread_count); for (i=0; i