Monday, January 23, 2017

Solaris Command to Show Long argument list of a Running Process

One of the problems with ps command, which is a popular tool to find any processes along with the grep command in the 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 appears at the tail end of the 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 processes in any UNIX operating system e.g. Solaris, Linux, IBM AIX, etc because Java process usually has a long list of arguments like system properties, JVM options, and name of the main class.

I have faced this problem quite a few times 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 the head of the long command-line argument and try to keep the 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 a higher chance of capturing the process by using grep with tail keywords.

By the way, if you are new to Linux then I also suggest you go through a comprehensive Linux course to learn some basics commands and fundamentals like Linux file system, permissions, and other basic things.

If you need an online course, I highly recommend Linux Mastery: Master the Linux Command Line in 11.5 Hours on Udemy. It's a very practical and hands-on course to learn Linux fundamentals in a quick time. It's also very affordable and you can buy in just $10 on Udemy flash sales which happen every now and then.

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
 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.

Further Learning
Linux Command Line Basics
Linux Command Line Interface (CLI) Fundamentals
Learn Linux in 5 Days and Level Up Your Career


Jan Andersen said...

Anonymous said...

In Linux, you can use following command to see full argument list :

cat /proc/$pid/cmdline

Post a Comment

Pepperjam Verification