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..???
-
2your vm implementation does that – Djole Jul 18 '14 at 14:57
-
Any language runtime implementation needs to make operating system calls. It could do that by using the C runtime library. That isn't actually necessary, just common. – Hans Passant Jul 18 '14 at 15:14
-
on linux systems you can enjoy to run your command with `strace` and monitor the system calls being performed. An analogue tool for windows is `procmon`. You will see that every time you perform I/O for example, the corresponding syscalls get involved. – Sigi Jul 18 '14 at 15:53
-
Quoting SICP, "The interpreter, which interprets and runs computer programs, is just another computer program." -- the java virtual machine is, **conceptually**, an interpreter for the java bytecode; jit is a speed optimization. More seriously, you could define&implement a ridiculously small vm (with eg a single instruction to print a given character) and notice if you end up calling those C library functions. – loreb Jul 18 '14 at 17:08
3 Answers
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

- 2,214
- 12
- 17
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.

- 2,858
- 23
- 22
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)
.

- 42,493
- 9
- 106
- 148