加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux – 如何在C中更改分叉进程的信息

发布时间:2020-12-14 00:59:35 所属栏目:Linux 来源:网络整理
导读:标题可能听起来有点奇怪,ps aux我看到了这个: root 20953 0.0 0.0 9528 1280 ? Ss Apr28 0:07 sendmail: accepting connections “接受连接”就像是sendmail进程的标题.它不是一个参数,因为cat / proc / 20953 / cmdline返回sendmail:接受连接(空格而不是0
标题可能听起来有点奇怪,ps aux我看到了这个:

root     20953  0.0  0.0   9528  1280 ?        Ss   Apr28   0:07 sendmail: accepting connections

“接受连接”就像是sendmail进程的标题.它不是一个参数,因为cat / proc / 20953 / cmdline返回sendmail:接受连接(空格而不是0x00):

# cat /proc/20953/cmdline |hexdump -C
00000000  73 65 6e 64 6d 61 69 6c  3a 20 61 63 63 65 70 74  |sendmail: accept|
00000010  69 6e 67 20 63 6f 6e 6e  65 63 74 69 6f 6e 73     |ing connections|
0000001f

/ proc fs中的参数用空字节分隔:

# cat /proc/26511/cmdline |hexdump -C
00000000  2f 62 69 6e 2f 62 61 73  68 00 2f 77 65 62 72 6f  |/bin/bash./webro|
00000010  6f 74 2f 70 72 6f 72 61  69 6c 2f 73 63 72 69 70  |ot/prorail/scrip|
00000020  74 73 2f 73 79 6e 63 6c  6f 6f 70 2e 73 68 00     |ts/syncloop.sh.|
0000002f

所以,当我在C中执行fork()时,如何设置这个进程信息,这样我才能识别出哪个进程是什么?

解决方法

sendmail有多种方式,具体取决于system.see中sendmail / conf.c中的setproctitle:

#define SPT_NONE        0       /* don't use it at all */
#define SPT_REUSEARGV   1       /* cover argv with title information */
#define SPT_BUILTIN     2       /* use libc builtin */
#define SPT_PSTAT       3       /* use pstat(PSTAT_SETCMD,...) */
#define SPT_PSSTRINGS   4       /* use PS_STRINGS->... */
#define SPT_SYSMIPS     5       /* use sysmips() supported by NEWS-OS 6 */
#define SPT_SCO         6       /* write kernel u. area */
#define SPT_CHANGEARGV  7       /* write our own strings into argv[] */

有关详细信息,请参阅conf.c中的setproctitle例程.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读