Java SIGQUIT output from DTrace

You may want to get stack traces for all threads and deadlock detector output from a Java process. You can press Ctrl-\\ on the terminal where Java program is running or run kill -QUIT <pid>. If there is no terminal for the process, then you may use jstack against that process. But, how about using DTrace on Solaris 10? - just to have some fun and to learn something... It appears that we can...

File: jstack.d

#!/usr/sbin/dtrace -qws

int interested;

:::BEGIN {
    interested = 0;
    system("kill -QUIT %d", $1);
}

proc:::signal-handle
/ pid == $1 && 
  arg0 == 3 /\*SIGQUIT\*/ / {
    interested = 1;
}

syscall::write:entry
/ pid == $1 &&
  arg0 == 1 &&  /\* writing to standard output \*/
  interested == 1  / {
    printf("%s", stringof(copyin(arg1, arg2)));
}

The above D-script may be run against Java process using the following command

   jstack.d <pid-of-the-Java-process>

How does this work?
  • -w option is used to enable destructive actions (sending signal by kill)
  • in the BEGIN probe, we send SIGQUIT to the Java process
  • On proc:::signal-handle probe we check SIGQUIT and turn on a global flag
  • On syscall::write:entry we print the content if the global flag is on and write is done on standard output (file descriptor check)
Comments:

Post a Comment:
Comments are closed for this entry.
About

sundararajan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
Links

No bookmarks in folder

Blogroll

No bookmarks in folder

News

No bookmarks in folder