ch4-thread-pid
Chapter_4 condvar | Chapter_5 |
thread-pid.c ALP, p. 87-88
#include <stdio.h> // for fprintf(), stderr, NULL
#include <unistd.h> // for getpid()
#include <pthread.h> // for pthread_t, pthread_create()
void * thread_function (void * arg);
int main()
{
pthread_t thread;
fprintf (stderr, "main() thread pid is %d\n", (int) getpid());
pthread_create (&thread, NULL, &thread_function, NULL);
while(1); /* Spin forever. */
return 0;
}
void * thread_function (void * arg)
{
fprintf (stderr, "child thread pid is %d\n", (int) getpid());
while(1); /* Spin forever. */
return NULL;
}
/*
gcc thread-pid.c -o thread-pid -lpthread
./thread-pid
main() thread pid is 100092
child thread pid is 100092
^C // Ctrl^C
*/
Chapter_4 condvar | BACK_TO_TOP | Chapter_5 |
Comments
Post a Comment