How to Increase the /Proc/Pid/Cmdline 4096 Byte Limit

How do I increase the /proc/pid/cmdline 4096 byte limit?

You can't change this dynamically, the limit is hard-coded in the kernel to PAGE_SIZE in fs/proc/base.c:

 274        int res = 0;
275 unsigned int len;
276 struct mm_struct *mm = get_task_mm(task);
277 if (!mm)
278 goto out;
279 if (!mm->arg_end)
280 goto out_mm; /* Shh! No looking before we're done */
281
282 len = mm->arg_end - mm->arg_start;
283
284 if (len > PAGE_SIZE)
285 len = PAGE_SIZE;
286
287 res = access_process_vm(task, mm->arg_start, buffer, len, 0);

PID hash table entries: 4096 (order: 12, 32768 bytes)?

PID hash table entries allocated as 2^N struct hlist_heads, which on a 64bit system are 8 bytes each. 2^12*8 = 32768.

Inode/Dentry caches are allocated as 2^N pages, usually 4096 bytes each. 2^15*4096 = 134217728.

This info is available in the source, kernel/pid.c and fs/inode.c respectively.

OCaml file I/O: why is add_channel returning empty content for /proc/ PID /cmdline?

The first version doesn't work because /proc/<PID>/cmdline (as well as any other file in the procfs virtual file system) is not a regular file, and in_channel_length

(** Return the size (number of characters) of the regular file .. *)

You may notice, for example, that a file or du also think that the cmdline file is empty:

$ file /proc/1/cmdline 
/proc/1/cmdline: empty

$ du -h /proc/1/cmdline
0 /proc/1/cmdline

Your first function will not always work on other non-regular files, for example on pipes.

How to get the command line args passed to a running process on unix/linux systems?

There are several options:

ps -fp <pid>
cat /proc/<pid>/cmdline | sed -e "s/\x00/ /g"; echo

There is more info in /proc/<pid> on Linux, just have a look.

On other Unixes things might be different. The ps command will work everywhere, the /proc stuff is OS specific. For example on AIX there is no cmdline in /proc.



Related Topics



Leave a reply



Submit