Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 576
Desert Ice Avatar asked May 08 '14 06:05

Desert Ice


People also ask

What is the maximum length for a file name in Linux?

On Linux: The maximum length for a file name is 255 bytes. The maximum combined length of both the file name and path name is 4096 bytes. This length matches the PATH_MAX that is supported by the operating system.

What is the maximum number of processes?

The kernel. pid_max value of 131072 above means the kernel can execute a maximum of 131,072 processes simultaneously. The vm. max_map_count value of 65530 above is the maximum number of memory map areas a process may have.

What is the maximum characters allowed in as UNIX file name?

The maximum combined length of the file name and path name is 1024 characters. The Unicode representation of a character can occupy several bytes, so the maximum number of characters that a file name might contain can vary. On Linux: The maximum length for a file name is 255 bytes.

What is Max user processes in Ulimit?

The maximum user processes (nproc) limit on Linux counts the number of threads within all processes that can exist for a given user. The default value of nproc is 1024 on some versions of Linux, which is generally an insufficient number of threads for all processes.


1 Answers

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.

like image 143
chrk Avatar answered Sep 28 '22 10:09

chrk