#include #include #include #include #include #include #include int main(void) { pid_t pid; int wstatus; pthread_key_t k1; pthread_key_t k2; pthread_key_t k3; char *val = malloc(1); initgroups("root", 0); pthread_key_create(&k1, NULL); pthread_setspecific(k1, val); printf("%d: k1=%d\n", getpid(), k1); pid = fork(); if (pid) { wait(&wstatus); return WEXITSTATUS(wstatus); } pthread_key_create(&k2, NULL); pthread_setspecific(k2, val); printf("%d: Hello after fork, k1=%d, k2=%d\n", getpid(), k1, k2); pid = fork(); if (pid) { wait(&wstatus); return WEXITSTATUS(wstatus); } pthread_key_create(&k3, NULL); pthread_setspecific(k3, val); printf("%d: Hello after fork2, k1=%d, k2=%d, k3=%d\n", getpid(), k1, k2, k3); if (k1 == k2 || k2 == k3) { printf("FAIL\n"); return 1; } else { printf("OK\n"); return 0; } }