问题
How can I see which system calls my Java program is making? Is there a tool that will do this on Linux?
回答1:
Use strace:
strace java your_program
回答2:
Use strace. But there is is trick for my case. Option -f
is needed. 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")
.
回答3:
see ltrace http://linux.die.net/man/1/ltrace
来源:https://stackoverflow.com/questions/10384850/seeing-all-the-system-calls-that-were-made-by-a-java-program