如何用 C 更改 Solaris 上分叉进程的名称?
我有一个服务器应用程序,它分叉多个子进程。当使用 ps
、top
或 prstat
显示进程时,它们的显示与父进程完全相同。我可以通过 pid
和 ppid
找出父子和子子,但这很快就会变得困难。我想稍微更改一下子进程的名称,以便我可以快速查看哪些进程执行什么操作。
我尝试了几种在 Linux 上都能完美运行的技巧,但在 Solaris 上却行不通。有谁知道如何做到这一点,最好是用纯 C 语言。
I have a server application that forks several child processes. When showing the processes with ps
, top
or prstat
they display exactly like the parent process. I can find out which is parent and child by their pid
and ppid
but it gets quickly difficult. I would like to change slightly the name of the child processes so that I can look quickly which does what.
I tried several tricks that all work flawlesly on Linux, but they do not on Solaris. Does anyone know how it is possible to do that and preferably in plain C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中一种方法是为子进程创建一个真正的可执行程序,并从 fork 中调用 exec 方法之一。
这样,分叉的进程将被新的可执行文件“替换”。
沿着这些思路:
One of the ways would be to create a real executable program for a child process and call one of the
exec
methods from the fork.This way the forked process will be "replaced" with the new executable file.
Something along these lines: