Linux中进程名的限制 为什么最多就只有15个字符

今天在使用Trace工具尝试追踪中间件的调用过程中,发现。。

呃呃,追到一群以前缀为名命名的进程。。

瞬间感觉很无语,还以为是自己操作不当。

查了一下,发现task struct进程名 buffer其实就是16个字节。那么15字节加截止NULL。妥了。 (可能可以通过配置内核来修改。)

原来菜的是供应商。没事名字起那么长纯粹不知道想表达什么。

话说回来 一般来讲 进程名称就是可执行文件的名称。

有人说名称是int main(int argc, char* argv[])里面的第一个 argv。。

搬运一下stackflow:

https://stackoverflow.com/questions/23534263/what-is-the-maximum-allowed-limit-on-the-length-of-a-process-name

What is the maximum allowed limit on the length of a process name?

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.


According to 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.

So I’d go for a 16 bytes long buffer.

EDIT:
Let me back this up a little more.

Each process in Linux corresponds to a struct task_struct in the kernel, which is defined in include/linux/sched.h.

In this definition, there’s a field 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 */

Its size, 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

Furthermore, quoting LDD3 page 22:

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

printk(KERN_INFO “The process is “%s” (pid %i)\n”,
current->comm, current->pid);
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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊苏C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值