设置线程/ proc / PID / cmdline? [英] Setting the thread /proc/PID/cmdline?

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

问题描述

Linux / NPTL 上,会创建线程作为某种进程。



我可以看到我的一些进程有一个奇怪的cmdline :

  cat / proc / 5590 / cmdline 
hald-addon-storage:polling / dev / scd0 sec)

你有一个想法,我如何能做到这一点,我的过程的每个线程?



p>感谢

解决方案

如果你想以可移植的方式做这件事,非常少的选项。



你必须做的是,你的调用者进程必须调用exec argv [0] 参数指向您希望在进程输出中看到的名称,以及指向实际可执行文件的文件名。



您可以从shell通过使用:

  exec -a这是我可爱的名字bash 

这将用一个名为的替换当前bash进程这是我可爱的名字 p>

对于在C中执行此操作,您可以查看 sendmail 的源代码或任何其他已经



某些操作系统有 setproctitle(3) API,其他一些允许您覆盖 argv [0] 的内容并显示结果。


On Linux/NPTL, threads are created as some kind of process.

I can see some of my process have a weird cmdline:

cat /proc/5590/cmdline 
hald-addon-storage: polling /dev/scd0 (every 2 sec)

Do you have an idea how I could do that for each thread of my process? That would be very helpful for debugging.

/me now investigating in HAL source

thanks

解决方案

If you want to do this in a portable way, something that will work across multiple Unix variations, there are very few options available.

What you have to do is that your caller process must call exec with the argv [0] argument pointing to the name that you would like to see in the process output, and the filename pointing to the actual executable.

You can try this behavior from the shell by using:

exec -a "This is my cute name" bash

That will replace the current bash process with one named "This is my cute name".

For doing this in C, you can look at the source code of sendmail or any other piece of software that has been ported extensively and find all the variations that are needed across operating systems to support this.

Some operating systems have a setproctitle(3) API, some others allow you to override the contents of argv [0] and show that result.

这篇关于设置线程/ proc / PID / cmdline?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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