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.
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.
Solaris command to display long arguments of running process
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.
Command to find out process which is using high CPU
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.[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
Solaris command to show a complete list of arguments of a running process
Here is the complete example of pargs command in Solaris which takes process id and displays the full list of argument which is used to run that process. This is a great tool to see full command with JVM options used to start a Java process in Solaris[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.
Other Linux and UNIX Tutorials for Beginners and Experienced
Thanks for reading this article so far. If you like this Linux and Solaris command tutorial and examples, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.
- 10 examples of date command in Linux (examples)
- How to get an IP address from the hostname (command)
- 10 examples of the xargs command in Linux (examples)
- 5 Free Courses to learn Linux for Beginners (Free courses)
- 10 examples of tar command in UNIX (examples)
- 10 examples of cut command in Linux (examples)
- 10 examples of Vim in UNIX (examples)
- 10 examples of lsof command in Linux (examples)
- How to create, update and delete soft link in UNIX (command)
- 5 examples of kill command in Linux (examples)
- 6 Free Courses to learn Bash scripting in-depth (free courses)
- 10 examples of chmod command in UNIX (examples)
- 10 examples of curl command in Linux (examples)
- 10 Books every Linux Power user should read (books)
- 5 examples of sort command in Linux (examples)
- 10 Best Linux Courses for Programmers and Developers (Courses)
Thanks for reading this article so far. If you like this Linux and Solaris command tutorial and examples, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html
ReplyDeleteIn Linux, you can use following command to see full argument list :
ReplyDeletecat /proc/$pid/cmdline