I am looking for a reliable way to get the full command line args passed to a process even when these are very long.
I do know about ps -f -p <pid>
and /proc/<pid>/cmdline
, both of which are usually up to the job. The problem is that both of these seem to truncate the command line args at 4096 chars, and I know for a fact that this one is longer ( It's a java application and the output truncates in the middle of the classpath string), and xargs --show-limits
tells me that my system allows up to 2094184 argument length.
Is there a way to do this?
UPDATE: I was able to get the full command line args string by making a wrapper that I placed earlier in the PATH and logged the args to a file before calling the right binary with the same args.
#!/bin/bash
file=/tmp/commandtrap-$$.log
/usr/bin/echo "$@" >$file
/usr/lib/jvm/java-7-openjdk/jre/bin/java "$@"
This is, however, an ugly workaround that only works because I could stop and run the process.
Ideally, there should be a way to obtain the full command without the need to close the running process (or disturbing it in any way)
ps -p $PID -o args=
– mikeserv Apr 03 '15 at 17:19$@
won't keep arguments correctly separated in the instance that one has spaces in. Change the java incovation to use/usr/lib/jvm/java-7-openjdk/jre/bin/java "$@"
and it will work more accurately. – Chris Davies Apr 03 '15 at 17:28-wwf
(I think those are the switches). 4k may be the limit though. – mikeserv Apr 03 '15 at 17:40ps -wwf
still truncates at around 4k – Chikitulfo Apr 03 '15 at 17:46