Truncated ps in FreeBSD

Applications like tomcat are notorious for their nice long command lines, e.g.

[someguy@somebox ~]$ ps wwwaux |grep java
someguy       1809  0.0 34.3 1000396 353764   0  I     7:27PM   2:18.69 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -server -Xmx700m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/common/endorsed -classpath :/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-logging-api.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
someguy 14052  0.0  0.1  3496  1008   1  S+    7:06PM   0:00.00 grep java
[someguy@somebox ~]$

However, by default in FreeBSD, the above command is more likely to result in output like:

[someguy@somebox ~]$ ps wwwaux |grep java
someguy 1809 0.0 34.3 1000396 353764 0 I 7:27PM 2:19.65 [java]
someguy 23888 0.0 0.1 3496 1016 1 S+ 7:22PM 0:00.00 grep java
[someguy@somebox ~]$

Reason being that in FreeBSD, ps has a default argument limit of 256 characters (PAGE_SIZE / 16), clearly not enough for our tomcat example. The place to adjust this is sysctl:

[someguy@somebox ~]$ sudo sysctl kern.ps_arg_cache_limit=2048
kern.ps_arg_cache_limit: 256 -> 2048

To make the above change permanent, just add it to /etc/sysctl.conf

somebox# sysctl -a | grep kern.ps_arg
kern.ps_arg_cache_limit: 256
somebox# echo "kern.ps_arg_cache_limit=2048" >> /etc/sysctl.conf
somebox# /etc/rc.d/sysctl reload
kern.ps_arg_cache_limit: 256 -> 2048
somebox# sysctl -a | grep kern.ps_arg
kern.ps_arg_cache_limit: 2048
somebox#

It doesn’t look like it’s getting changed anytime soon. 256 is still the default in RELENG_8. You can see more info at http://www.freebsd.org/cgi/query-pr.cgi?pr=120749