Monday, April 20, 2009

All about the process

Oftentimes, when we are debugging a system, it is helpful to gather data on the various processes running on a system. One of the first commands that I learned in Unix was ps. Since most of my QA career has centered around testing java applications, I have typed the following command uncountable times: ps -ef | grep java. This usually results in this type of information. Note that the second column is the PID, which is helpful in case you need to kill a process. Also note that the last column will get truncated if it's too long.

bash-3.00# ps -ef | grep java
noaccess 709 1 0 Mar 31 ? 10:37 /usr/java/bin/java -server -Xmx128m -XX:+UseParallelGC -XX:ParallelGCThreads=4
root 12309 1 0 15:26:21 ? 59:33 /usr/jdk/instances/jdk1.6.0_12/jre/bin/amd64/java -server -Xmx30g -Xms30g -XX:+
root 12549 12540 0 09:27:33 pts/1 0:00 grep java
root 12273 1 0 14:37:37 ? 59:22 /usr/jdk/instances/jdk1.6.0_12/jre/bin/amd64/java -server -Xmx30g -Xms30g -XX:+
root 6463 1 0 Apr 10 ? 113:57 /usr/jdk/instances/jdk1.6.0_12/bin/java -server -Xms512m -Xmx512m CommandLineRe


Another useful command for java processes only is jps. It will give you results with the PID as well.

bash-3.00# /usr/java/bin/jps
12541 Jps
12273 DirectoryServer
12309 DirectoryServer
709 Bootstrap
6463 CommandLineResourceMonitorClient


You can also try jps -Vv to get more information as well. See the jps man page. The last useful command that I have in my repertoire is pargs. Say you know the PID, you can get all of the arguments that were used. E.g.,

bash-3.00# pargs 12273
12273: /usr/jdk/instances/jdk1.6.0_12/jre/bin/amd64/java -server -Xmx30g -Xms30g -XX:+
argv[0]: /usr/jdk/instances/jdk1.6.0_12/jre/bin/amd64/java
argv[1]: -server
argv[2]: -Xmx30g
argv[3]: -Xms30g
argv[4]: -XX:+UseConcMarkSweepGC
argv[5]: -XX:+CMSConcurrentMTEnabled
argv[6]: -XX:+CMSParallelRemarkEnabled
argv[7]: -XX:+CMSParallelSurvivorRemarkEnabled
argv[8]: -XX:ParallelCMSThreads=8
argv[9]: -XX:CMSMaxAbortablePrecleanTime=10
argv[10]: -XX:CMSInitiatingOccupancyFraction=80
argv[11]: -XX:+UseParNewGC
argv[12]: -XX:+UseBiasedLocking
argv[13]: -XX:+UseLargePages
argv[14]: -XX:+HeapDumpOnOutOfMemoryError
argv[15]: -Dcom.unboundid.directory.server.scriptName=start-ds
argv[16]: com.unboundid.directory.server.core.DirectoryServer
argv[17]: --configClass
argv[18]: com.unboundid.directory.server.extensions.ConfigFileHandler
argv[19]: --configFile
argv[20]: /ds/cynthia/repl/1/config/config.ldif