Reputation: 409
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..???
Upvotes: 2
Views: 841
Reputation: 43688
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)
.
Upvotes: 0
Reputation: 2914
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
Upvotes: 0
Reputation: 2292
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
Upvotes: 0