0
点赞
收藏
分享

微信扫一扫

打印进程的所有线程


#include <iostream>
#include <sys/prctl.h>

void th1(void)
{
prctl(PR_SET_NAME, __FUNCTION__);
while(1){
std::this_thread::sleep_for(std::chrono::milliseconds(100);
}

int main(int argc, char *argv[])
{
printf("pid: %d\n", getpid());
prctl(PR_SET_NAME, "LY");//修改主线程的名称,其实也就修改了进程名。
std::thread Thread1(th1);
Thread1.detach();
while(1){
//sleep(1);
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
select(0, NULL, NULL, NULL, &tv);
}
}

top -Hp `pgrep LY` //打印进程的线程(cpu,内存)使用情况


举报

相关推荐

Python终止所有线程

进程、线程的理解

0 条评论