Tuesday, March 5, 2013

Date Command                                    Cron Job in Linux

In Linux, we are using the ps command to check process information and to check machine's performance we use top command. But some times, in case of java processes, we need more information. These commands are not sufficient to get that much of information of particular java process.

Depends on your requirement you can use following commands to get required information of particular java processes.  Jstat, Jmap, Jinfo commands are very useful to analyze to java process performance as well as memory mapping.


Jstat command is a Java virtual machine statistics monitoring tool. Please see below example for how to use command and its output.

Jstat -gc <PID>

root@Hello:~# jstat -gc 9020
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
6912.0 6528.0 16.0 0.0 117632.0 108377.4 393216.0 7188.1 17280.0 17262.5 24 0.103 0 0.000 0.103

root@Hello:~# jstat -class 9020
Loaded Bytes Unloaded Bytes Time
3284 3939.7 0 0.0 2.26

There are many options for this command you can use man page for getting all options of this command. For better understanding of jstat output short forms like S0C, S1C click on this link. Jstat Command in Linux.


Jmap is used to check memory mapping of particular java process. Jmap can give memory mapping of class wise of that java program as well. We can use this command as follows:

usage of this command as

jmap <OPTONS> <PID>

or

jmap <PID>

root@Hello:~# jmap 9020
Attaching to process ID 9020, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.0-b12

using thread-local object allocation.
Parallel GC with 2 thread(s)

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 536870912 (512.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 3
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 134217728 (128.0MB)

Heap Usage:
PS Young Generation
Eden Space:
capacity = 120455168 (114.875MB)
used = 115808768 (110.44384765625MB)
free = 4646400 (4.43115234375MB)
96.14263125680087% used
From Space:
capacity = 7077888 (6.75MB)
used = 16384 (0.015625MB)
free = 7061504 (6.734375MB)
0.23148148148148148% used
To Space:
capacity = 6684672 (6.375MB)
used = 0 (0.0MB)
free = 6684672 (6.375MB)
0.0% used
PS Old Generation
capacity = 402653184 (384.0MB)
used = 7360656 (7.0196685791015625MB)
free = 395292528 (376.98033142089844MB)
1.8280386924743652% used
PS Perm Generation
capacity = 17694720 (16.875MB)
used = 17676760 (16.857872009277344MB)
free = 17960 (0.01712799072265625MB)
99.8985007957176% used


Another use of this jmap command to check all java classes as :

root@Hello:~# jmap -permstat 9020
Attaching to process ID 9020, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.0-b12
9569 intern Strings occupying 747072 bytes.
finding class loader instances ..Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
done.
computing per loader stat ..done.
please wait.. computing liveness....liveness analysis may be inaccurate ...
class_loader classes bytes parent_loader alive? type

<bootstrap> 1673 7167072 null live <internal>
0x94c0ac88 1 1800 0x9464a2d0 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94b4d988 1 1768 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad3738 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0ab70 1 1168 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x945e09f0 98 607840 0x945e0a38 live sun/misc/Launcher$AppClassLoader@0x8c775510
0x9485b068 1 1784 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c110b8 1 1768 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0abe0 1 1768 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94a3cf38 1 1168 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x945e0960 720 3903736 0x945e09a8 live org/apache/catalina/loader/StandardClassLoader@0x8cb28578
0x94c0a8d0 1 1808 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0ac18 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad5090 1 1808 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x9488bb88 171 890600 0x945f97d0 live org/apache/catalina/loader/WebappClassLoader@0x8cee3928
0x94ad53a0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a940 1 1768 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94857948 1 1784 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad2d80 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a978 1 1768 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c11c58 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0aac8 1 1800 0x9464a2d0 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a860 1 1768 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0aa58 1 1168 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad1748 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad1128 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a9e8 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad3a48 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0ab38 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94852000 2 24344 null dead javax/management/remote/rmi/NoCallStackClassLoader@0x8ca81c88
0x94c0acc0 1 1808 0x9464a2d0 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad59c0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0aa20 1 1816 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a908 1 1800 0x9464a2d0 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0ac50 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94857650 1 1784 null dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94ad6ce0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x945e09a8 661 2994208 0x945e09f0 live org/apache/catalina/loader/StandardClassLoader@0x8cb28578
0x94ad56b0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94c0a898 1 1808 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x94851b50 4 9544 null dead javax/management/remote/rmi/NoCallStackClassLoader@0x8ca81c88
0x94ad33a0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x9464a2d0 800 3519760 0x945f97d0 live org/apache/catalina/loader/WebappClassLoader@0x8cee3928
0x94ad1a58 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x945f97d0 0 0 0x945e09a8 live org/apache/catalina/loader/StandardClassLoader@0x8cb28578
0x945fda98 0 0 0x945e09f0 live java/util/ResourceBundle$RBClassLoader@0x8caedee8
0x94ad6ff0 1 1800 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0
0x945e0a38 0 0 null live sun/misc/Launcher$ExtClassLoader@0x8c72c0a8
0x94c0ab00 1 1768 0x945e0960 dead sun/reflect/DelegatingClassLoader@0x8c6317a0

total = 60 4178 19203080 N/A alive=9, dead=51 N/A


If you need more information regarding the Jmap command then please click on next link : Jmap Commandin Linux.

Jstack Command

Jstack command used to trace Java process stack trace.

Usage of jstack as follows :

jstack <PID>

Its output is very bigger thats why I couldn't paste here. Please check your own to exact output as above format.

Click here to know more about: While Loop in Shell Scripting

And most important command for java process is that jinfo.


Jinfo command gives configuration information of java process.

Usage:

jinfo <PID>

jinfo <OPTIONS> <PID>

example of jinfo command as :

root@Hello:~# jinfo 9020
Attaching to process ID 9020, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.0-b12
Java System Properties:

java.runtime.name = OpenJDK Runtime Environment
sun.boot.library.path = /usr/lib/jvm/java-5-openjdk/jre/lib/i586
java.vm.version = 20.0-b12
shared.loader = ${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar
java.vm.vendor = Sun Microsystems Inc.
java.vendor.url = http://java.sun.com/
java.rmi.server.randomIDs = true
path.separator = :
tomcat.util.buf.StringCache.byte.enabled = true
java.util.logging.config.file = /hello/test/tomcat/conf/logging.properties
java.vm.name = OpenJDK Server VM
file.encoding.pkg = sun.io
sun.java.launcher = SUN_STANDARD
user.country = IN
sun.os.patch.level = unknown
com.sun.management.jmxremote.port = 3080
java.vm.specification.name = Java Virtual Machine Specification
user.dir = /hello/test/tomcat/bin
java.runtime.version = 1.6.0_24-b24
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.endorsed.dirs = /hello/test/tomcat/common/endorsed
os.arch = i386
java.io.tmpdir = /hello/test/tomcat/temp
line.separator =

java.vm.specification.vendor = Sun Microsystems Inc.
java.naming.factory.url.pkgs = org.apache.naming
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/lib/jvm/java-5-openjdk/jre/lib/i586/server:/usr/lib/jvm/java-5-openjdk/jre/lib/i586:/usr/lib/jvm/java-6-openjdk/jre/../lib/i386:/usr/java/packages/lib/i386:/usr/lib/jni:/lib:/usr/lib
java.specification.name = Java Platform API Specification
java.class.version = 50.0
sun.management.compiler = HotSpot Tiered Compilers
os.version = 3.0.0-12-generic
com.sun.management.config.file = /hello/test/tomcat/conf/management.properties
user.home = /root
catalina.useNaming = true
user.timezone = Asia/Kolkata
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.6
catalina.home = /hello/test/tomcat
java.class.path = :/hello/test/tomcat/bin/bootstrap.jar:/hello/test/tomcat/bin/commons-logging-api.jar
user.name = root
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.
java.vm.specification.version = 1.0
org.xmldb.common.xml.queries.XPathQueryFactory = org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.home = /usr/lib/jvm/java-6-openjdk/jre
sun.arch.data.model = 32
user.language = en
java.specification.vendor = Sun Microsystems Inc.
java.vm.info = mixed mode
java.version = 1.6.0_24
java.ext.dirs = /usr/lib/jvm/java-6-openjdk/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /hello/test/tomcat/common/endorsed/commons-collections-3.1.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/netx.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/plugin.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/modules/jdk.boot.jar:/usr/lib/jvm/java-6-openjdk/jre/classes
server.loader = ${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar
java.vendor = Sun Microsystems Inc.
catalina.base = /hello/test/tomcat
java.security.auth.login.config = ../conf/jaas.conf
file.separator = /
java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi
common.loader = ${catalina.home}/common/classes,${catalina.home}/common/i18n/*.jar,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans.
sun.cpu.isalist =

VM Flags:

-Djava.security.auth.login.config=../conf/jaas.conf -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/hello/test/tomcat/conf/logging.properties -Dcom.sun.management.config.file=/hello/test/tomcat/conf/management.properties -Dcom.sun.management.jmxremote.port=3080 -Xms512m -Xmx512m -XX:NewRatio=3 -XX:+UseAdaptiveSizePolicy -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/internet/apps/cmt/outofmemory.hprof -Djava.endorsed.dirs=/hello/test/tomcat/common/endorsed -Dcatalina.base=/hello/test/tomcat -Dcatalina.home=/hello/test/tomcat -Djava.io.tmpdir=/hello/test/tomcat/temp



If you want to more information of this command and click on next link : Jinfo command inLinux.


Logical Volume Manager                       Difference of Unix and Linux       Type Command
Posted by Machindra Dharmadhikari On 3/05/2013 07:35:00 PM No comments READ FULL POST

Thursday, December 27, 2012

Linux Boot Loader                                                           Features of Bash Shell

It is very easy to learn bash shell scripting. There are different Unix shells like bash, ksh, zsh, sh etc. Please make sure that which shell do you want to use while running the script, because syntax of each shell might be different. Before going to develop shell script, your logic or flow of the script should be clear then only you can develop shell script very easily. It is very important to have clear understanding of when or where not to use shell script. 

 

For Fibonacci series shell script, need to know the exact number series. It will be as :

1              1              2              3              5              8              13           21            34          etc.

Please see below is the script to get desired output. 

######################Fibonacci.sh###############################

echo "How many numbers do you want of Fibonacci series ?"

  read total

  x=0

  y=1

  i=2

  echo "Fibonacci Series up to $total terms :: "

  echo "$x"

  echo "$y"

  while [ $i -lt $total ]

  do

      i=`expr $i + 1 `

      z=`expr $x + $y `

      echo "$z"

      x=$y

      y=$z

  done

Click to  know more about: Difference of Linux and Unix

#####################################################################

Now just save it as Fibonacci.sh and give the input as how many numbers you want of . Your output will be as follows: 

#####################################################################

root@hello:~/ctier/test/JBoss#

root@hello:~/ctier/test/JBoss# ./Fibnonacci.sh

How many numbers do you want of Fibonacci series ?

10

Fibonacci Series up to 10 terms ::

0

1

1

2

3

5

8

13

21

34

root@hello:~/ctier/test/JBoss#

#####################################################################

Before developing this script you should have clear understandings of while loop in shell script  and addition of numbers i.e. mathematical calculations in shell script.


mpstat command in Linux                                                        Ubuntu 12.10 features
Posted by Machindra Dharmadhikari On 12/27/2012 04:53:00 PM 1 comment READ FULL POST

Wednesday, December 26, 2012

Difference of Unix and Linux                                   Unix Shells

If you are already familiar with C or C++ coding then it is very easy to understand while loop in shell scripting. The Shell script while loop is same as other languages but different with syntax only. In bash shell scripting, while loop helps to run loop till the criteria fails. It is very useful when you want to run same command multiple times with change of some of the commands or its input.
The basic syntax of while loop in linux as follows:

while [ condition ]
do

                Our command 1;
                Command 2
                Command3
done

 Above while loop works as : if condition is satisfied then control comes inside the while loop and it will execute the command1, command then command3. And finally loop will exit.

While loop example in Linux:

root@hello:~/hello/test/test1# i=1;
root@hello:~/hello/test/test1#  while [ $i -lt 5 ]
> do
> echo $i;
> (( i++ ));
> done
1
2
3
4
root@hello:~/ctier/test/test1#

There are some changes in syntax of while loop as shell changes. In bash scripting, above syntax will work but in ksh it will not.
For KSH, you need to run the while as follows:

while [[ condition ]] ;
do
command 1 ;
command 2;
done

while loop with multiple conditions as follows:
while [ "$var1" != "$var2" || "$var1" == "$var3" || "$var2" != "$var4" ]
do
                commands here;
done
You can use counter inside the while loop as :
let counter=counter+1;

or

(( i++))
Posted by Machindra Dharmadhikari On 12/26/2012 07:18:00 PM 1 comment READ FULL POST

Wednesday, December 19, 2012

Recover deleted files in Linux                                    10 steps to create Logical Volume


Cygwin is the best application which creates unix like environment in Windows OS. We can run almost all commands on Cygwin. Processing of files in windows will be easy if we use unix commands to process.

You can use openssh server in cygwin and create password less connection as well. There are many features of Cygwin that we will discuss in other article.

Please see below  for  brief information about installation of cygwin.

How to install cygwin ?
1.        It is very easy step. Go to this link Download Cygwin. 
2.       Download setup.exe only.
3.       Run the setup.exe and you can see first pop up as follows:
 


Click here to know more about: Jstat Command in Linux


4.       Select Install from Local directory, if you have already downloaded all packages otherwise select first option i.e. Install from Internet and click next.
 
5.       After that you will get next window where setup is asking for root directory if you have selected the Install from local directory. Otherwise give the path where you want to keep all cygwin related files and then click on next.
 

6.       Now it will ask for Internet settings if you have i.e. for proxy settings if you have. Otherwise select Direct Connection option.
 
7.       Now you will get mirror list. Select any mirror and click on next.
 
8.       It is the last step and most important step about Cygwin installation. Please be careful while selecting the packages which you need with cygwin. If you have not selected respective package then you will not get the commands of that package in your cygwin and you will get error message like "Command not found". If you are going to select all packages then Cygwin will take too much time to complete and you will install unnecessary packages as well.
 

After selection of packages, installation process will start. click on next and then finish. 
and then you will get the desktop icon for Cygwin Launch. Double click on this and Cygwin will start  and start to run unix commands on Windows
 

If you need any help regarding Cygwin then you can reach me on linuxconcepts@gmail.com.


FTP server Concept                  Bash Shell features                      File System in Linux


Posted by Machindra Dharmadhikari On 12/19/2012 06:38:00 PM 3 comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner