ps最多只能打印任何进程的命令行的4096个字符


19

当我为一个Java进程grep时,我得到的输出低于输出,但它被限制为4096个字符,这导致grep输出中未显示实际的进程名称(即kafka.Kafka)。

这是grep的限制吗?有什么方法可以打印超过4096个字符的字符?

ps -ef | grep java

java -Xmx6G -Xms6G-服务器-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 。罐:/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/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/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/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/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


你可以参考这篇文章吗? unix.stackexchange.com/questions/101681/…–
Kamaraj

那没有解决问题。我猜这里的限制是4096个字节。
zer0Id0l

3
看起来您可以通过使用通配符语法来使类路径缩短很多,请参见stackoverflow.com/questions/219585/…,或者您也可以使用env var CLASSPATH将其完全(完全)移出命令行;这些中的任何一个都有很好的机会使命令行足够短以查看您的类名。或对于Java进程,如果您的UID可以访问并且您拥有或获取JDK,则jps无论命令行截断如何(至少在Linux上),都显示类名。
dave_thompson_085 '17

1
@slebetman我确定OP知道,但是可能生成此脚本的脚本不是
cat

1
标题意味着ps -ef打印更多,但是grep正在改变它。这似乎是没有根据的。
查尔斯·达菲

Answers:


35

这不是的限制grep,而是/proc/PID/cmdline(从技术上来说,是设计决定,不是限制)。/proc/PID/cmdline包含该过程的完整命令行,主要命令和参数用ASCII NUL分隔,文件也以NUL结尾。因此,grep如果有匹配项,将打印整个文件内容。(以ps -ef获取此文件的内容CMD)。

最大长度在(Linux)内核中硬编码为PAGE_SIZE

static int proc_pid_cmdline(struct task_struct *task, char * buffer)
{
        int res = 0;
        unsigned int len;
        struct mm_struct *mm = get_task_mm(task);
        if (!mm)
                goto out;
        if (!mm->arg_end)
                goto out_mm;    /* Shh! No looking before we're done */

        len = mm->arg_end - mm->arg_start;

        if (len > PAGE_SIZE)
                len = PAGE_SIZE;

因此,对于这样的系统,为4096字节:

% getconf PAGE_SIZE
4096

同样,如果您有多字节字符,那么您可以想象,字符数将少于4096。


7
@ zer0Id0l您不能更改PAGE_SIZE:这是硬件的属性。您必须设计一些具有较大页面大小的新硬件,或者(非常容易……)cmdline通过实施适当的内存映射或复制来消除将内容截断为一页的限制。
吉尔斯(Gilles)'所以别再邪恶了'

4
FWIW,当Giles说这是硬件的属性时,他的意思是它是CPU的MMU的属性。因此,您需要使用页面大小大于4k的MMU的CPU或设计使用页面大小大于4k的外部MMU的体系结构(并为其构建主板和BIOS)(请记住,过去MMU曾经是外部芯片)或设计自己的CPU(加上编译器等)。另一个选择是修改Linux内核,使其proc_pid_cmdline不使用PAGE_SIZE
slebetman

此设计限制不需要存在。随意编写另一个没有它的proc_pid_cmdline。
约书亚
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.