如何查看我的Java程序正在调用哪些系统?是否有一个工具可以在Linux上执行此操作?
答案 0 :(得分:10)
使用strace。但是我的情况有诀窍。需要选项-f
。例如,以下代码:
public class Foo {
public static void main (String [] args) {
System.out.println("XXX");
}
}
运行javac Foo.java
进行编译后,strace java Foo 2>&1 | grep write
不打印任何内容。但strace -f java Foo 2>&1 | grep write
打印:
[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
显示为System.out.println("XXX")
进行的系统调用。
答案 1 :(得分:8)
使用strace:
strace java your_program
答案 2 :(得分:1)
请参阅ltrace http://linux.die.net/man/1/ltrace