微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 进程名称长度的最大允许限制是多少?

进程名称允许的最大长度是多少?我正在从/ proc / [pid] / stat文件中读取进程名称,我想知道我需要的最大缓冲区.

我很确定有一个可配置的限制,但却无法找到它的位置.

解决方法

根据 man 2 prctl

PR_SET_NAME (since Linux 2.6.9)

Set the name of the calling thread,using the value in the location pointed to by (char *) arg2. The name can be up to 16 bytes long,and should be null-terminated if it contains fewer bytes.

所以我要去一个16字节长的缓冲区.

编辑:

让我再说一点.

Linux中的每个进程对应于内核中的struct task_struct,它在include / linux / sched.h中定义.

在这个定义中,有一个字段char comm[TASK_COMM_LEN],根据注释引用不包括路径的可执行文件名:

char comm[TASK_COMM_LEN]; /* executable name excluding path
                                 - access with [gs]et_task_comm (which lock
                                   it with task_lock())
                                 - initialized normally by setup_new_exec */

它的大小TASK_COMM_LEN在上面的同一个文件here中定义为16个字节:

/* Task command name length */
#define TASK_COMM_LEN 16

此外,引用LDD3第22页:

the following statement prints the process ID and the command name of the current
process by accessing certain fields in struct task_struct :

06002

The command name stored in current->comm is the base name of the program file
(trimmed to 15 characters if need be) that is being executed by the current process.

原文地址:https://www.jb51.cc/linux/395076.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐