多线程程序获取进程号和线程号

线程库<pthread.h>

 

获取程序的进程号

getpid()

cout<<"main function pid:"<<getpid()<<endl;

 

获取线程函数的线程号

#include <sys/types.h>
cout<<"route thread function pid:"<<gettid()<<endl;

注意gettid()要写在线程函数内部

 

posted @ 2022-03-10 09:41  Wangtn  阅读(255)  评论(0编辑  收藏  举报