Linux多线程编程学习代码记录(代码已上传gitee,点个Star也可以哦!)
https://gitee.com/chenshao777/linux_thread.git
【Linux多线程编程-自学记录】
01.线程ID与进程ID
02.创建线程
03.主线程与子线程生命周期
04.线程链接-pthread_join
05.取消线程
06.向线程发送信号-sigaction
07.线程清除
08.Linux多线程互斥量
09.Linux多线程之读写锁
10.条件变量
01.线程ID与进程ID
笔记:
获取进程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);
}