查看由Java程序进行的所有系统调用

时间:2012-04-30 13:52:37

标签: java linux system-calls

如何查看我的Java程序正在调用哪些系统?是否有一个工具可以在Linux上执行此操作?

3 个答案:

答案 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)