$ whatis pstack

The set of commands that work on proc (psudo) based file systems. The list of ptools are: proc, pflags, pcred, pldd, psig, pstack, pfiles, pwdx, pstop, prun, pwait, ptime - proc tools


Examples:

	To run the command pstack, I need root access in order to be able to read the stack area of the 
higher level PIDs such as the ones I am using below. Therefore, I make sure I am logged in as root.

# id
uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)
	I run the ps command to get parent shell ($$) pid. 
# ps
  PID TTY         TIME CMD
19012 pts/2       0:00 bash
19018 pts/2       0:00 ps

	Now, I run the pstack on pid 19012 which is the same as $$.

# pstack 19012
19012:  /usr/bin/bash -i
 fee2329c __forkx  (0, 8118c10, 8047b78, fee0c724, 1) + c
 fee0c735 fork     (8130488, 0, 8047bc8, 80bc38b, 20002, 0) + 1d
 0808ea98 make_child (8130228, 0, 1132, 80829c1) + 90
 08082a19 ???????? (812c268, 0, 81308a8, ffffffff, ffffffff)
 08081a81 ???????? (8130248, ffffffff, ffffffff, 0, 81345a8, 3)
 0807d407 execute_command_internal (8130108, 0, ffffffff, ffffffff, 81345a8) + 687
 0807cb9b execute_command (8130108, 8118c10, 8047db8, 806b333) + 5b
 0806b3ab reader_loop (fecf0180, 8119990, 8119e5c, 0, 81199b4, 2) + 1bf
 0806915b main     (2, 8047e24, 8047e30, 806888f) + 7df
 080688ed _start   (2, 8047ed4, 8047ee2, 0, 8047ee5, 8047ee9) + 7d

	I can also use the pstack command to see the stack contents for core files.

# ls -l core
-rw------- 1 wahid staff 2004119 2011-04-19 16:29 core

# file core
core:           ELF 32-bit LSB core file 80386 Version 1, from 'testme'

# pstack core
core 'core' of 27028:   ./testme
 08050d5d main     (1, 8047d2c, 8047d34, 8050de0, 0, 0) + 99
 08050b67 _start   (1, 8047df0, 0, 8047df9, 8047e36, 8047e46) + 83

	Now, I use the commands below to get the stack buffer values for the pid 1 or /sbin/init binary.
# ps -ef | grep -i init	
    root     1     0   0   Apr 03 ?           0:04 /sbin/init
# pstack 1
1:      /sbin/init
 feee1147 pollsys  (806c588, 1, 80475d8, 0)
 fee86718 poll     (806c588, 1, 493e0, 8054503) + 4c
 080545e4 main     (1, 8047f6c, 8047f74, feffb8f4) + 418
 0805412d _start   (1, 8047fe0, 0, 0, 7d8, 8047feb) + 7d

	Here is an example of the pstack for pid 11020 which is the gdm-simple-slave in this case.

# pstack 11020
11020:  /usr/lib/gdm-simple-slave --display-id /org/gnome/DisplayManager/Displ
-----------------  lwp# 1 / thread# 1  --------------------
 feef2455 pollsys  (80b5ff8, 7, 0, 0)
 fee96e06 poll     (80b5ff8, 7, ffffffff, fed681c8, 8099c8c) + 4c
 fed681e0 g_poll   (80b5ff8, 7, ffffffff, fed59d66) + 24
 fed5a19b g_main_context_iterate (8099c88, 1, 1, 8092aa8) + 443
 fed5a801 g_main_loop_run (809f670) + 1dd
 0805c8fa main     (1, 8047ddc, 8047dec, feffb8f4) + 2ca
 0805c42d _start   (3, 8047e88, 0, 0, 0, 8047ed2) + 7d
-----------------  lwp# 2 / thread# 2  --------------------
 feef25b5 read     (8, fe2eef50, 14)
 fed5bcf9 child_watch_helper_thread (0, 80a15c8, 208, fed8248a) + 29
 fed825af g_thread_create_proxy (80a15c8, fef70000, fe2eefe8, feeed61e) + 133
 feeed673 _thrp_setup (fe1e0240) + 9b
 feeed920 _lwp_start (fe1e0240, 0, 0, 0, 0, 0)

# ps -ef | grep -i 11020
    root 11020   981   0   Apr 13 ?           0:00 /usr/lib/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display2
    root 11021 11020   0   Apr 13 vt/2       16:13 /usr/bin/Xorg :0 -nolisten tcp -br -auth /tmp/gdm-auth-cookies-CpaO6b/auth-for-
     gdm 11063 11020   0   Apr 13 ?           0:00 /usr/bin/gnome-session --autostart=/usr/share/gdm/autostart/LoginWindow/
    root 11087 11020   0   Apr 13 ?           0:00 /usr/lib/gdm-session-worker

Please click on " man pstack. " to see the Manual Page for this command.