How do I increase the /proc/pid/cmdline 4096 byte limit?
Solution 1
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);
Solution 2
For looking at Java processes jps is very useful.
This will give you the main class and jvm args:
jps -vl | grep <pid>
Solution 3
You can use jconsole
to get access to the original command line without all the length limits.
Solution 4
It is possible to use newer linux distributions, where this limit was removed, for example RHEL 6.8 or later
"The /proc/pid/cmdline file length limit for the ps command was previously hard-coded in the kernel to 4096 characters. This update makes sure the length of /proc/pid/cmdline is unlimited, which is especially useful for listing processes with long command line arguments. (BZ#1100069)"
user27635
Updated on June 02, 2022Comments
-
user27635 almost 2 years
For my Java apps with very long classpaths, I cannot see the main class specified near the end of the arg list when using ps. I think this stems from my Ubuntu system's size limit on /proc/pid/cmdline. How can I increase this limit?
-
user27635 over 15 yearsnope, even with ww, it truncates at 4096. I think ps is reading from /prod/pid/cmdline which is also truncated.
-
Jay over 15 yearsNote that this can be adjusted if you're willing to recompile the kernel to do so (see my comment for a how-to link).
-
user2522201 over 15 yearsAnything can be adjusted if you are willing to recompile the kernel but it still can't be changed dynamically.
-
We Are All Monica over 14 years-1. The first part of your comment is not correct. On my system,
getconf ARG_MAX
says thatARG_MAX = 2097152
(meaning that my maximum argument length is 2 megabytes). However,/proc/$pid/cmdline
is truncated toPAGE_SIZE
which is 4096. Your how-to link does NOT cover this specific situation - I have no idea if changing the relevant bit infs/proc/base.c
would cause other problems. -
HaveAGuess over 13 yearsEven worse for me. Truncates quickly
-
Greg Price almost 13 years@HaveAGuess, wfm - it shows the main class, no matter how obscenely long the classpath may be, which is what the OP asked for. (It can also optionally show other arguments.)
-
stivlo over 12 yearsit may work and it increases the length limit, but for really huge command line it doesn't work anymore and gets truncated (just experienced that).
-
AJP about 10 years@Jay unfortunately it seems it is not unlimited, it is limited to 4096 characters.
-
t0r0X about 10 yearsWorks for me too, shows all parameters for insanely long (more than 4096 chars) Weblogic command lines (Linux 64bit). Thanks Kevin!
-
Camilo Martin almost 10 yearsRecompiling the kernel feels like moving to a new house because you didn't like the previous one's sofa.
-
ernesto over 9 yearsI am trying
jps
to see full classpath of hadoop java processes... for some reasonjps
won't even show me the classpath! -
Steve about 7 yearsThanks, this worked for me. I needed to add the -m option to see the command line arguments.
-
javabrett over 6 years
jps -lvm
even better for me - them
is needed to show command-line args (not JVM args) passed to your Javamain
method. -
JdeBP about 6 yearsThis was fixed in June 2015 and this answer is now out of date.