设置线程名字:
int CLinuxSysTools::setThreadTitle(const char* threadName)
{
#ifdef LINUX
return prctl(PR_SET_NAME, (unsigned long) threadName, 0, 0, 0) ;
#else
return 0 ;
#endif
}
显示线程名字:
1, 通过proc查看任务状态
(base) root@ansen-VirtualBox:/proc# pidof 'pevt'
16760
(base) root@ansen-VirtualBox:/proc# cd 16760/
(base) root@ansen-VirtualBox:/proc/16760# cd task
(base) root@ansen-VirtualBox:/proc/16760/task# cat ./*/status | grep -E 'Name|Pid'
Name: pevt
Pid: 16760
PPid: 3230
TracerPid: 0
Name: EE0-TestEE:
Pid: 16761
PPid: 3230
TracerPid: 0
Name: EE1-TestEE2
Pid: 16762
PPid: 3230
TracerPid: 0
Name: EE2-TestEEloop
Pid: 16763
PPid: 3230
TracerPid: 0
Name: EE3-TestEEloop
Pid: 16764
PPid: 3230
TracerPid: 0
Name: EE4-TestEEloop
Pid: 16765
PPid: 3230
TracerPid: 0
Name: EE5-TestEEloop
Pid: 16766
PPid: 3230
TracerPid: 0
Name: EE6-TestEEloop
Pid: 16767
PPid: 3230
TracerPid: 0
Name: EE7-TestEEloop
Pid: 16768
PPid: 3230
TracerPid: 0
Name: EE8-TestEEloop
Pid: 16769
PPid: 3230
TracerPid: 0
Name: EE9-TestEEloop
Pid: 16770
PPid: 3230
TracerPid: 0
Name: EE10-TestEEloop
Pid: 16771
PPid: 3230
TracerPid: 0
Name: EE11-TestEEloop
Pid: 16772
PPid: 3230
TracerPid: 0
Name: pevTimerSystem
Pid: 16773
PPid: 3230
TracerPid: 0
Name: gpsd_cliet
Pid: 16774
PPid: 3230
TracerPid: 0
(base) root@ansen-VirtualBox:/proc/16760/task#
2, 通过pstree -a 查看
3, 通过ps 查看
(base) root@ansen-VirtualBox:/proc/16760/task# ps -eLf c | grep -E 'EE|pevt'
root 16760 3230 16760 0 15 17:30 pts/1 Sl+ 0:02 pevt
root 16760 3230 16761 0 15 17:30 pts/1 Sl+ 0:00 EE0-TestEE:
root 16760 3230 16762 0 15 17:30 pts/1 Sl+ 0:00 EE1-TestEE2
root 16760 3230 16763 0 15 17:30 pts/1 Sl+ 0:00 EE2-TestEEloop
root 16760 3230 16764 0 15 17:30 pts/1 Sl+ 0:00 EE3-TestEEloop
root 16760 3230 16765 0 15 17:30 pts/1 Sl+ 0:00 EE4-TestEEloop
root 16760 3230 16766 0 15 17:30 pts/1 Sl+ 0:00 EE5-TestEEloop
root 16760 3230 16767 0 15 17:30 pts/1 Sl+ 0:00 EE6-TestEEloop
root 16760 3230 16768 0 15 17:30 pts/1 Sl+ 0:00 EE7-TestEEloop
root 16760 3230 16769 0 15 17:30 pts/1 Sl+ 0:00 EE8-TestEEloop
root 16760 3230 16770 0 15 17:30 pts/1 Sl+ 0:00 EE9-TestEEloop
root 16760 3230 16771 0 15 17:30 pts/1 Sl+ 0:00 EE10-TestEEloop
root 16760 3230 16772 0 15 17:30 pts/1 Sl+ 0:00 EE11-TestEEloop
本文介绍了在Linux系统下如何使用`prctl`函数设置线程名称,并通过`/proc`文件系统以及`pstree`和`ps`命令来查看线程的名称。展示了如何定位和读取进程任务状态来获取线程详细信息。
18万+

被折叠的 条评论
为什么被折叠?



