Java에서 직접 syscall을 호출하는 방법이 있습니까, 아니면 기본 메소드를 먼저 호출해야합니까?
답변
기본 메소드를 사용해야하지만 직접 구현할 필요는 없습니다. Java에는 JNI (Java Native Access) 라는 JNI 변형 이 있으므로 JNI 인터페이스를 감쌀 필요없이 공유 라이브러리에 직접 액세스 할 수 있으므로이를 사용하여 glibc와 직접 인터페이스 할 수 있습니다.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class Test {
    public interface CStdLib extends Library {
        int syscall(int number, Object... args);
    }
    public static void main(String[] args) {
        CStdLib c = (CStdLib)Native.loadLibrary("c", CStdLib.class);
        // WARNING: These syscall numbers are for x86 only
        System.out.println("PID: " + c.syscall(20));
        System.out.println("UID: " + c.syscall(24));
        System.out.println("GID: " + c.syscall(47));
        c.syscall(39, "/tmp/create-new-directory-here");
    }
}
답변
기본 메소드 또는이를위한 라이브러리를 사용해야합니다.