15

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

2
  • 3
    Could you use strace java your_program? Commented Apr 30, 2012 at 13:55
  • I tried it and it worked.Thanks Commented Apr 30, 2012 at 15:25

3 Answers 3

18

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").

Sign up to request clarification or add additional context in comments.

Comments

16

Use strace:

strace -f java your_program 

or

strace -f -p <pid of your java program> 

Comments

1

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

2 Comments

ptrace might be more useful in this case
@MikeKwan ltrace is for library function calls and ptrace is to examine other process' memory. strace is the one for system calls.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.