Skip to content

Instantly share code, notes, and snippets.

@kostja
Created February 8, 2015 18:26
Show Gist options
  • Save kostja/767622d554c676a35454 to your computer and use it in GitHub Desktop.
Save kostja/767622d554c676a35454 to your computer and use it in GitHub Desktop.
pthread_self() returns the same value across after fork()
kostja@atlas ~ % gcc -pthread foo.c; ./a.out
thread id: 140508398954304
thread id: 140508398954304
thread id: 140508398954304
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
int main()
{
printf("thread id: %llu\n", (unsigned long long) pthread_self());
fork();
printf("thread id: %llu\n", (unsigned long long) pthread_self());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment