#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
void
printids(const char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("%s pid = [%u] tid = [%u] [0x%x]\n",
s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}
void *
thr_fn(void *arg)
{
printids("new thread:");
return ((void *)0);
}
int
main()
{
pthread_t ntid;
int err;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if(err != 0)
printf("不能创建线程[%s]\n",strerror(err));
printids("main thread:");
sleep(3);
exit(0);
}
[root@localhost pthread]# gcc test.c -o test
/tmp/ccq2Mbxs.o: In function `main':
test.c:(.text+