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

19,407

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)"

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/6.8_Release_Notes/new_features_kernel.html

Share:
19,407
user27635
Author by

user27635

Updated on June 02, 2022

Comments

  • user27635
    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
    user27635 over 15 years
    nope, even with ww, it truncates at 4096. I think ps is reading from /prod/pid/cmdline which is also truncated.
  • Jay
    Jay over 15 years
    Note 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
    user2522201 over 15 years
    Anything can be adjusted if you are willing to recompile the kernel but it still can't be changed dynamically.
  • We Are All Monica
    We Are All Monica over 14 years
    -1. The first part of your comment is not correct. On my system, getconf ARG_MAX says that ARG_MAX = 2097152 (meaning that my maximum argument length is 2 megabytes). However, /proc/$pid/cmdline is truncated to PAGE_SIZE which is 4096. Your how-to link does NOT cover this specific situation - I have no idea if changing the relevant bit in fs/proc/base.c would cause other problems.
  • HaveAGuess
    HaveAGuess over 13 years
    Even worse for me. Truncates quickly
  • Greg Price
    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
    stivlo over 12 years
    it 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
    AJP about 10 years
    @Jay unfortunately it seems it is not unlimited, it is limited to 4096 characters.
  • t0r0X
    t0r0X about 10 years
    Works for me too, shows all parameters for insanely long (more than 4096 chars) Weblogic command lines (Linux 64bit). Thanks Kevin!
  • Camilo Martin
    Camilo Martin almost 10 years
    Recompiling the kernel feels like moving to a new house because you didn't like the previous one's sofa.
  • ernesto
    ernesto over 9 years
    I am trying jps to see full classpath of hadoop java processes... for some reason jps won't even show me the classpath!
  • Steve
    Steve about 7 years
    Thanks, this worked for me. I needed to add the -m option to see the command line arguments.
  • javabrett
    javabrett over 6 years
    jps -lvm even better for me - the m is needed to show command-line args (not JVM args) passed to your Java main method.
  • JdeBP
    JdeBP about 6 years
    This was fixed in June 2015 and this answer is now out of date.