Pages

Monday, March 24, 2014

Solaris P-commands

As we know , every thing in linux is a file . what ever we open or execute we deal with files. With the /proc virtual file system, even processes may be treated like files.

/proc (or procfs) is a virtual file system that allows us to examine processes like files. This means that /proc allows us to use file-like operations and intuitions when looking at processes. /proc does not occupy disk space; it is located in working memory.

Under the /proc location we see a lot of number which are nothing but the pid(process ID) for the running process. Under this pid directory, we can see some more sub directories which will give many details about the process running. We can get the same details using the Process command or P-commands in Solaris.

The available P-commands in Solaris are, 
  • pcred: Display process credentials (eg EUID/EGID, RUID/RGID, saved UIDs/GIDs)
  • pfiles: Reports fstat() and fcntl() information for all open files. This includes information on the inode number, file system, ownership and size.
  • pflags: Prints the tracing flags, pending and held signals and other /procstatus information for each LWP.
  • pgrep: Finds processes matching certain criteria.
  • pkill: Kills specified processes.
  • pldd: Lists dynamic libraries linked to the process.
  • pmap: Prints process address space map.
  • prun: Starts stopped processes.
  • prstat: Display process performance-related statistics.
  • ps: List process information.
  • psig: Lists signal actions.
  • pstack: Prints a stack trace for each LWP in the process.
  • pstop: Stops the process.
  • ptime: Times the command; does not time children.
  • ptree: Prints process genealogy.
  • pwait: Wait for specified processes to complete.
  • pwdx: Prints process working directory.

And here are some of the snippets using the above P-commands.

Display Process credentials
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# pcred 1289
1289:   e/r/suid=0  e/r/sgid=0
        groups: 0 1 2 3 4 5 6 7 8 9 12

Display the File Opened by a process
oracle@solaris_11X:~# pfiles 1289
1289:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
  Current rlimit: 65536 file descriptors
   0: S_IFCHR mode:0666 dev:551,0 ino:25690120 uid:0 gid:3 rdev:49,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
      offset:0
   1: S_IFREG mode:0644 dev:174,65544 ino:5047 uid:0 gid:0 size:2872
      O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE
      /home/oracle/Downloads/apache-tomcat-7.0.52/logs/catalina.out
      offset:2872


Display the flags
oracle@solaris_11X:~# pflags 1289
1289:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
        data model = _ILP32  flags = ORPHAN|MSACCT|MSFORK
 /1:     flags = ASLEEP  lwp_wait(0x2,0x8046cb4)
 /2:     flags = ASLEEP  accept(0x32,0xce2ae320,0xce2ae380,0x1)
        sigmask = 0x00000004,0x00000000,0x00000000


Display the linked libraries by a process
oracle@solaris_11X:~# pldd 1289
1289:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
/lib/libthread.so.1
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/jli/libjli.so
/lib/libdl.so.1
/usr/lib/libc/libc_hwcap3.so.1
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/client/libjvm.so
/lib/libsocket.so.1
/usr/lib/libsched.so.1
/lib/libm.so.1
/usr/lib/libCrun.so.1
/lib/libdoor.so.1
/lib/libm.so.2
/lib/libnsl.so.1
/lib/libmd.so.1
/lib/libmp.so.2
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libverify.so
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libjava.so
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/native_threads/libhpi.so
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libzip.so
/usr/lib/locale/en_US.UTF-8/en_US.UTF-8.so.3
/usr/lib/locale/common/methods_unicode.so.3
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libmanagement.so
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libj2pkcs11.so
/usr/lib/libpkcs11.so.1
/lib/libcryptoutil.so.1
/usr/lib/security/pkcs11_softtoken.so.1
/usr/lib/libsoftcrypto.so.1
/lib/libgen.so.1
/usr/jdk/instances/jdk1.6.0/jre/lib/i386/libnet.so


Display the process address space of a process
oracle@solaris_11X:~# pmap 1289
1289:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
08045000      12K rwx--    [ stack ]
08050000      44K r-x--  /usr/jdk/instances/jdk1.6.0/bin/java
0806A000       4K rwx--  /usr/jdk/instances/jdk1.6.0/bin/java
0806B000    7064K rwx--    [ heap ]

top command in solaris
prstat
 PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
 719 oracle     84M   57M sleep   46    0   0:02:23  10% Xorg/3
 933 oracle     90M   20M sleep   54    0   0:00:30 6.7% gnome-terminal/2

print the signals from a process
oracle@solaris_11X:~# psig 1289
1289:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
HUP     caught  UserHandler     RESTART HUP,INT,QUIT,ILL,TRAP,ABRT,EMT,FPE,BUS,SEGV,SYS,PIPE,ALRM,TERM,USR1,USR2,CLD,PWR,WINCH,URG
INT     ignored


Print the Threads of a Process
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# pstack 1661
1661:   /usr/bin/java -Djava.util.logging.config.file=/home/oracle/Downloads/a
-----------------  lwp# 1 / thread# 1  --------------------
 ceaa21a7 lwp_wait (2, 8046ce4)
 cea9988c _thrp_join (2, 0, 8046d50, 1) + 63
 cea999db thr_join (2, 0, 8046d50) + 23


stop a process
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# pstop 1661
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# ps aex 1661
   PID TT       S  TIME COMMAND
1661 pts/2    T  0:05 /usr/bin/java
-Djava.util.logging.config.file=/home/oracle/Downloads/apache-tomcat-7.0.52/conf/logging.properties

Check the State “T” which says it is stopped

Start the Process
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# prun 1661
oracle@solaris_11X:~/Downloads/apache-tomcat-7.0.52/bin# ps aex 1661
   PID TT       S  TIME COMMAND
1661 pts/2    R  0:05 /usr/bin/java
-Djava.util.logging.config.file=/home/oracle/Downloads/apache-tomcat-7.0.52/conf/logging.properties

Check the State “R” which says it is started.


More to Come , Happy Learning J