Debian Codegraph @

listings/chapter-4/thread-pid.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <pthread.h>
8 #include <stdio.h>
9 #include <unistd.h>
10
11 void* thread_function (void* arg)
12 {
13 fprintf (stderr, "child thread pid is %d\n", (int) getpid ());
14 /* Spin forever. */
15 while (1);
16 return NULL;
17 }
18
19 int main ()
20 {
21 pthread_t thread;
22 fprintf (stderr, "main thread pid is %d\n", (int) getpid ());
23 pthread_create (&thread, NULL, &thread_function, NULL);
24 /* Spin forever. */
25 while (1);
26 return 0;
27 }