Seeing all the system calls that were made by a Java program

帅比萌擦擦* 提交于 2019-12-01 17:55:36

Use strace:

strace java your_program

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!