【Linux多线程编程-自学记录】01.线程ID与进程ID

Linux多线程编程学习代码记录(代码已上传gitee,还请各位兄弟点个Star哦!)

https://gitee.com/chenshao777/linux_thread.git


笔记:
获取进程id
getpid()

获取线程id
pthread_self()

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    
    
	pid_t pid;  //定义进程id变量
	pthread_t tid;  //定义线程id变量

	pid = getpid();  //获取进程id
	tid = pthread_self();  //获取线程id	
	
	printf("进程id is %u, 线程id is %x\n",pid,tid);
}

猜你喜欢

转载自blog.csdn.net/HuangChen666/article/details/130454496