-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.2.c
39 lines (32 loc) · 716 Bytes
/
11.2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* creates one thread and pirnts the process and thread IDs of the new thread and the in initail thread. */
#include <stdio.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
pthread_t ntid;
void printids(const char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("%s pid %lu tid %lu (0x%lx)\n", s, (unsigned long)pid, (unsigned long)tid, (unsigned long)tid);
}
void *thr_fn(void *arg)
{
printids("new thread: ");
return ((void *)0);
}
int main()
{
int err;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if (err != 0)
{
printf("pthread_create error\n");
return -1;
}
printids("main thread:");
sleep(1);
return 0;
}