Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I grep for a java process I get below output but it's limited to 4096 characters which results to actual process name(which is kafka.Kafka) not shown in grep output.

Is this a limitation of grep? Is there any way to print characters beyond 4096 limit?

ps -ef | grep java

java -Xmx6G -Xms6G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.awt.headless=true -Xloggc:/x/kafka/data01/kafka-app-logs/kafkaServer-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dkafka.logs.dir=/x/kafka/data01/kafka-app-logs -Dlog4j.configuration=file:./../config/log4j.properties -cp :/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/aopalliance-repackaged-2.4.0-b34.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/argparse4j-0.5.0.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/connect-api-0.10.1.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/connect-file-0.10.1.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/connect-json-0.10.1.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/connect-runtime-0.10.1.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/guava-18.0.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/hk2-api-2.4.0-b34.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/hk2-locator-2.4.0-b34.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/hk2-utils-2.4.0-b34.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-annotations-2.6.0.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-core-2.6.3.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-databind-2.6.3.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-jaxrs-base-2.6.3.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-jaxrs-json-provider-2.6.3.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jackson-module-jaxb-annotations-2.6.3.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javassist-3.18.2-GA.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javax.annotation-api-1.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javax.inject-1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javax.inject-2.4.0-b34.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javax.servlet-api-3.1.0.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/javax.ws.rs-api-2.0.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-client-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-common-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-container-servlet-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-container-servlet-core-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-guava-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-media-jaxb-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jersey-server-2.22.2.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-continuation-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-http-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-io-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-security-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-server-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-servlet-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-servlets-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jetty-util-9.2.15.v20160210.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/jopt-simple-4.9.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/kafka_2.10-0.10.1.1.jar:/x/home/bmcuser/kafka-paypal/kafka_2.10-0.10.1.1/bin/../libs/kafka_2.10-0.10.1.1-so

share|improve this question
    
can you refer this post. unix.stackexchange.com/questions/101681/… – Kamaraj 6 hours ago
    
That didn't solve the issue. I guess the limitation here is 4096 bytes. – zer0Id0l 6 hours ago
    
when you say.. it didn't solve the issue... you get the same output ? – Kamaraj 6 hours ago
    
yep, got same output. – zer0Id0l 6 hours ago
    
It looks like probably you could make your classpath a lot shorter by using wildcard syntax, see stackoverflow.com/questions/219585/…, or you can definitely move it (entirely) off the commandline using env var CLASSPATH; either of those has a good chance of making the commandline short enough to see your classname. Or for Java processes only, if your UID has access and you have or get JDK, jps shows classname regardless of commandline truncation (at least on Linux). – dave_thompson_085 4 mins ago
up vote 13 down vote accepted

This is not a limitation of grep, but of /proc/PID/cmdline. /proc/PID/cmdline contains the complete command line of the process, with main command and arguments separated by ASCII NUL, and the file ends in NUL too. So, grep will print the whole file content if there is a match. (ps -ef gets the content of this file as CMD).

The maximum length is hardcoded in the (Linux) kernel to the PAGE_SIZE:

203 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
204 {
205         int res = 0;
206         unsigned int len;
207         struct mm_struct *mm = get_task_mm(task);
208         if (!mm)
209                 goto out;
210         if (!mm->arg_end)
211                 goto out_mm;    /* Shh! No looking before we're done */
212 
213         len = mm->arg_end - mm->arg_start;
214  
215         if (len > PAGE_SIZE)
216                 len = PAGE_SIZE;

hence 4096 bytes for such a system:

% getconf PAGE_SIZE
4096

Also, if you have multibyte character(s), the number of characters would be less than 4096, as you can imagine.

share|improve this answer
    
Thanks! Now I know. So I guess, only way to fix it would be to change the PAGE_SIZE on host? – zer0Id0l 6 hours ago
2  
@zer0Id0l You need to recompile the kernel to change the PAGE_SIZE. So, either way, recompile !! – heemayl 6 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.