Linux pstack command summary, linuxpstack command
The pstack command is used to display the stack trace of a process. The pstack command must be run by the owner or root account of the corresponding process. You can use pstack to determine where the process is suspended. This command has only one parameter, that is, pid. For more information about pstack, see the man manual, as shown below:
[root@DB-Server ~]# man pstack
PSTACK(1) Linux Programmer’s Manual PSTACK(1)
NAME
pstack - print a stack trace of a running process
SYNOPSIS
pstack pid
DESCRIPTION
pstack attaches to the active process named by the pid on the command line, and prints out an execution stack trace. If ELF symbols exist in the binary (usually the case
unless you have run strip(1)), then symbolic addresses are printed as well.
If the process is part of a thread group, then pstack will print out a stack trace for each of the threads in the group.
SEE ALSO
nm(1), ptrace(2), gdb(1)
AUTHORS
Ross Thompson <ross@whatsis.com>
Red Hat, Inc.
Red Hat Linux Dec 17 2004 PSTACK(1)
(END)
For example, we can use the pstack command to view the stack trace of the Oracle listening process, as shown below:
1: first find the process Number of the listening process
[oracle@DB-Server~]$ ps -ef | grep lsn
oracle 12027 11806 0 11:18 pts/1 00:00:00 grep lsn
oracle 31440 1 0 Mar04 ? 00:01:41 /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr LISTENER -inherit
2: Write the stack trace information of the listening process to the file lsn_pstack.log.
[oracle@DB-Server~]$ pstack 31440 >> lsn_pstack.log
[oracle@DB-Server~]$ pstack 31440 >> lsn_pstack.log
[oracle@DB-Server~]$ pstack 31440 >> lsn_pstack.log
[oracle@DB-Server~]$
3: as shown below, we can see that the function call relationship is: main-> nsglma-> nsevwait-> ntevque-> ntevpque-> poll.
[oracle@DB-Server~]$ more lsn_pstack.log
#0 0x0000003c7d0cb65f in poll () from /lib64/libc.so.6
#1 0x00007f82c63292e7 in ntevpque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#2 0x00007f82c6326aab in ntevque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#3 0x00007f82c62fc81e in nsevwait () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#4 0x00000000004108d9 in nsglma ()
#5 0x0000000000405abd in main ()
#0 0x0000003c7d0cb65f in poll () from /lib64/libc.so.6
#1 0x00007f82c63292e7 in ntevpque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#2 0x00007f82c6326aab in ntevque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#3 0x00007f82c62fc81e in nsevwait () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#4 0x00000000004108d9 in nsglma ()
#5 0x0000000000405abd in main ()
#0 0x0000003c7d0cb65f in poll () from /lib64/libc.so.6
#1 0x00007f82c63292e7 in ntevpque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#2 0x00007f82c6326aab in ntevque () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#3 0x00007f82c62fc81e in nsevwait () from /u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1
#4 0x00000000004108d9 in nsglma ()
#5 0x0000000000405abd in main ()
[oracle@DB-Server~]$