我可以设置的pthreads / Linux的一个线程的名称? [英] Can I set the name of a thread in pthreads/Linux?

查看:110
本文介绍了我可以设置的pthreads / Linux的一个线程的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在Linux中设置线程的名称的方法吗?

Is there any way of setting the name of a thread in Linux?

我的主要目的是这将有助于在调试时,也很好,如果该名称是通过例如暴露的/ proc / $ PID /任务/ $ TID /...

My main purpose is it would be helpful while debugging, and also nice if that name was exposed through e.g. /proc/$PID/task/$TID/...

推荐答案

使用使用prctl(2)功能与选项 PR_SET_NAME (见的文档)。

Use the prctl(2) function with the option PR_SET_NAME (see the docs).

请注意,该文档是有点混乱。他们说,

Note that the docs are a bit confusing. They say

有关调用进程将进程名

,但由于螺纹是重量轻的过程在Linux(LWP),一个线程处于这种情况下,一个过程

but since threads are light weight processes (LWP) on Linux, one thread is one process in this case.

您可以看到线程名与 PS -o CMD 的/ proc / $ PID / STAT 之间在()

You can see the thread name with ps -o cmd or in /proc/$PID/stat between the ():

4223 (kjournald) S 1 1 1 0...

这篇关于我可以设置的pthreads / Linux的一个线程的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆