14

How can I see which system calls my Java program is making? Is there a tool that will do this on Linux?

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
Ragini
  • 1,509
  • 7
  • 28
  • 42

3 Answers3

17

Use strace. But there is is trick for my case. Option -f is needed and is the same as --follow-forks. For example, the following code:

public class Foo {
    public static void main (String [] args) {
        System.out.println("XXX");    
    }
}

After running javac Foo.java to compile it, strace java Foo 2>&1 | grep write print nothing. But strace -f java Foo 2>&1 | grep write prints:

[pid 11655] write(3, "0x63", 4)         = 4
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(3, "\0", 1)           = 1
[pid 11655] write(1, "XXX", 3XXX)          = 3
[pid 11655] write(1, "\n", 1

[pid 11655] write(1, "XXX", 3XXX) = 3 shows the system call made for System.out.println("XXX").

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Jingguo Yao
  • 7,320
  • 6
  • 50
  • 63
16

Use strace:

strace -f java your_program

or

strace -f -p <pid of your java program>
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
1

see ltrace http://linux.die.net/man/1/ltrace

Luca
  • 4,223
  • 1
  • 21
  • 24