Rabu, 14 Januari 2015

Solaris Command to Show Long argument list of a Running Process



One of the problem with ps command, which is a popular tool to find any processes along with grep command in Solaris operating system is that it doesn't show full command line argument of process. This means if you are doing grep on any text which appear at tail end of long command line, you will likely not able to capture that process by using ps and grep. This is dangerous because it may lead you to assume that certain process is not running and you may restart it again, despite its being running and only because you didn't find the process. This is quite common while running Java process in any UNIX operating system e.g. Solaris, Linux, IBM AIX etc because Java process usually has long list of arguments e.g. system properties, JVM options,  and name of main class. I have faced this problem quite few time even after using ps -ef  option. Until now I have not found any compelling solution for this problem which will work on all UNIX systems, except for Solaris, which  I am going to share with you guys. So, my only advice is to put the keyword in head of long command line argument and try to keep Java command line as small as possible. Also prefer using ps -auxww over ps -ef,  former better display long command line than later and you have higher chance of capturing the process by using grep with tail keywords.






Solaris command to display long arguments of running process



How to see full argument list of a running process in Solaris

Putting important keywords e.g. name of your Java process at the start of argument list is Ok but what if you really need full command line argument of any process in UNIX environment? Sure there must be some command which can give you complete command line of a running process, no? Well, I didn't know about it despite using UNIX and Linux from long time until recently when I really needed full command line argument a Java process which is taking most of CPU from that machine. I found the process id (PID) of that Java process using prstat command and then I tried to see that process using ps command for that process but didn't see full command line. Few Google search reveals a command called pargs which shows full command line of a process if you know process id (PID).  It's not a replacement of ps command but still a good tool to see full command line of any process in Solaris. Here is an example of how you can use prstat and pargs command in Solaris to find a running process and show its complete list of argument.



Command to find out process which is using high CPU



[test@localhost] > prstat -scpu
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
28525 test 860M 615M sleep 59 0 80:35:02 3.5% java/833
19681 test 431M 361M cpu0 30 0 2:57:43 3.1% ksh/2




You can see here that our Java process 28525 is using 3.5% of CPU and it has 833 threads. Now we need to find out complete list of arguments passed to this process from command line while starting it. It doesn't matter if it is started from a script or directly because in UNIX, start-up script will be a different process than your Java application.



Solaris command to show complete list of arguments of a running process



[test@localhost]> pargs 28525
pargs: Couldn't determine locale of target process.
pargs: Some strings may not be displayed properly.
28525: /opt/jdk1.6.0_22/bin/java -server -Dsun.rmi.dgc.cli
argv[0]: /opt/jdk1.6.0_22/bin/java -server -Dsun.rmi.dgc.cli
argv[1]: -server
argv[2]: -Dsun.rmi.dgc.client.gcInterval=3600000
argv[3]: -Dsun.rmi.dgc.server.gcInterval=3600000
argv[4]: -verbose:gc
argv[5]: -Xloggc:./logs/GC.log
argv[6]: -XX:+PrintGCTimeStamps
argv[7]: -verbose:gc
argv[8]: -Xloggc:./logs/GC.log
argv[9]: -XX:+PrintGCTimeStamps
argv[12]: -Xms2048M
argv[13]: -Xmx2048M
argv[14]: -cp



Bingo, now you can see that what argument has passed to process with PID 28525. You can see that first argument is Java executable itself. You can find out your JDK location as well as Java version number e.g. here JDK is located at /opt partition and Java version is JDK 1.6.0_22. Next you can see the argument pass to JVM e.g. -server shows that its running on server mode. You can also see other garbage collection options, startup and max memory provided to server and it's classpath. I have not shown full classpath here purposefully but when you run this command in Solaris by yourself, you will see all the arguments passed to your Java process.





That's all on How to show long command line of a process running on Solaris operating system. This is a very useful command to troubleshoot Java process with long list of arguments e.g. you can check what JVM parameters has been passed to your Java process, value of key configuration parameters and you can also find how much maximum memory is allocated to your Java application.  























Source:http://javarevisited.blogspot.com/2015/01/solaris-command-to-show-long-argument-of-running-process.html

Tidak ada komentar:

Posting Komentar