简体   繁体   中英

system calls using c library

Generally, systems provide a library or API that sits between normal programs and the operating system. On Unix-like systems, that API is usually part of an implementation of the C library (libc), such as glibc, that provides wrapper functions for the system calls.Functions like write(),read(),open().. are used to make system calls from a C program.Does it mean that if a java program has to make a system call then at the lowest level it has to call these C library functions ?If so, then how..???

If you really need to you can do that with the Java Native Interface (JNI).

Beware it is not for the feint of heart; the JVM usually can do what you want.

One use-case of JNI is using OpenSSL for crypto in Java; this used to be substantially faster when I tested it (it was nearly 10 years ago).

http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

I assume you don't want to know how to do it in Java since the question is not tagged as a java question.

So the libc is the right way to do it but, for information purposes, in linux, you can use the syscall function. The syscall function can use an Int 0x80 signal, a sysenter instruction or something else depending on the platform.

Introduction to System Calls in Linux

In Java, this is done using native Methods . These are methods declared with the native modifier and (similarly to abstract methods) no body, whose real implementation is written in a platform-dependent language, usually C.

Additional native method implementations may be runtime loaded using System.loadLibrary(String libraryName) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM