进程名称长度的最大允许限制是多少? [英] What is the maximum allowed limit on the length of a process name?
问题描述
进程名称允许的最大长度是多少?我正在从/proc/[pid]/stat
文件中读取进程名称,我想知道我需要的最大缓冲区.
What is the maximum length allowed for a process name? I am reading the process name from /proc/[pid]/stat
file and i would like to know the maximum buffer that i would need.
我很确定有一个可配置的限制,但无法确定它在哪里.
I am pretty sure there is a limit which is configurable but just can't find out where this is.
推荐答案
根据
PR_SET_NAME(自Linux 2.6.9起)
PR_SET_NAME (since Linux 2.6.9) 使用(char *)arg2指向的位置中的值设置调用线程的名称. 名称的长度最多为16个字节,如果包含的字节较少,则应以空值结尾. 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个字节的长缓冲区. So I'd go for a 16 bytes long buffer. 让我再备份一点. Linux中的每个进程对应于 Each process in Linux corresponds to a 在此定义中,存在一个字段 In this definition, there's a field 它的大小 Its size,
此外,在第22页引用LDD3:
Furthermore, quoting LDD3 page 22: ... ... 以下语句显示当前的进程ID和命令名称
通过访问 the following statement prints the process ID and the command name of the current
process by accessing certain fields in The command name stored in 这篇关于进程名称长度的最大允许限制是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
include/linux/sched.h
中定义的.struct task_struct
in the kernel, which is defined in include/linux/sched.h
.char comm[TASK_COMM_LEN]
, which according to the comment refers to the executable name excluding the path: 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
在上面的同一头文件此处为 16个字节:TASK_COMM_LEN
, is defined above in the same header file, here, to be 16 bytes:/* Task command name length */
#define TASK_COMM_LEN 16
struct task_struct
中的某些字段进行处理:struct task_struct
:printk(KERN_INFO "The process is \"%s\" (pid %i)\n",
current->comm, current->pid);
current->comm
中存储的命令名称是程序文件的基本名称
当前进程正在执行的操作(如果需要,可剪裁为15个字符).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.