-1

If we want to create native Linux apps, we need to use glibc C APIs. If I'm correct the glibc APIs themselves call the Linux C APIs. Now I have two questions:

  1. Is that Linux C API available for programmers or is the glibc the lowest we can go? (lowest in C, not the assembly language)

  2. What do other higher-level frameworks use? (.NET Core, Java, Python, etc) Do they use glibc APIs or do they directly talk to the Kernel? (like glibc itself)

Sasan
  • 3,840
  • 1
  • 21
  • 34
  • Define "lowest". `What do other higher-level frameworks use?` You can't generalize. Each and every one high-level "framework" uses something else. And `.NET` definitely does not use glibc... and usually programs use the C library that is available, it's not necessarily glibc, it can be anything else. – KamilCuk Jul 08 '21 at 09:50
  • There are a few Linux distros that do not use GNU libc. For example, Alpine Linux uses musl libc. Then of course there are other systems built that use the Linux kernel such as Android that uses Bionic. Other libc implementations for Linux include uClibc and possibly NewLib (but NewLib is mostly for systems using bare-metal or RTOS-style micro-kernels). – Ian Abbott Jul 08 '21 at 11:11
  • The Linux syscall interface differs for different architectures (including different sets of syscalls, different syscall numbers, or different behavior for a particular syscall), so the libc implementation abstracts away a lot of those implementation details (although there are still differences such as the sizes of various system types and the sizes of fundamental C types such as `long int` and pointers, and the alignment sizes of the fundamental C types). – Ian Abbott Jul 08 '21 at 11:19

2 Answers2

1

My first question would be, "why do you want to?". glibc provides the C standard library. From the gnu site iself,

The GNU C Library project provides the core libraries for the GNU system and GNU/Linux systems, as well as many other systems that use Linux as the kernel.

That said, you could try to use the Linux system calls, syscalls(2). See the (linux man page).

As for other frameworks, well, for python at least I have seen written:

The Linux Python interpreter is itself written in Linux/Unix C, and uses the operating system C kernel calls.

(see this answer on quora, which I found by googling "how does Python interact with the linux kernel?".)

Ian Abbot added in a comment here that the Quora quote did not explain how it uses syscalls (which is via libc). He suggested that you can tell it uses libc by examining the output of ldd /usr/bin/python and seeing libc.so.6 in the output (if it is using current glibc). I tried this and saw it as well. This is also true for /usr/bin/java...

Basya
  • 1,477
  • 1
  • 12
  • 22
  • Well I'm asking this because I read everywhere that most languages and frameworks are written in C. Also I'm reading "The Linux Programming Interface" book and it is based on the `glibc` (so far). If I understood correctly there is a hidden layer here that no one mentions it. If some people want to create a new language and framework, is `glibc` all they need or do they have to dig deeper? – Sasan Jul 08 '21 at 10:07
  • If you were writing it in C, you would use glibc presumably. If you were writing it in another language (assembly?) you'd probably have to use syscall, which is what glibc uses. – Basya Jul 08 '21 at 10:19
  • The Python interpreter also uses the system's libc. – Ian Abbott Jul 08 '21 at 14:41
  • @IanAbbott - that makes sense, and is what I would have thought, except for what I saw someone else write (but it is an unsubstantiated change). If you have a source for this to suggest, I can edit it in. – Basya Jul 08 '21 at 14:43
  • 1
    The answer on quora doesn't say *how* it uses syscalls (which is via libc). You can tell it uses libc by examining the output of `ldd /usr/bin/python` and seeing `libc.so.6` in the output (if it is using current glibc). – Ian Abbott Jul 08 '21 at 14:52
  • @IanAbbott - thank you. I didn't think of doing that. I edited it in. – Basya Jul 08 '21 at 15:02
0

If we want to create native Linux apps, we need to use glibc C APIs

Well, that statement is false. To write a portable C programming language program, you would use C standard library. glibc is one of the implementations of the C standard library, but there are other implementations. To write "native Linux apps", you can write it in assembly, or use other library, or use a different programming language.

If I'm correct the glibc APIs themselves call the Linux C APIs

System calls are the way to communicate with the kernel. Also with Linux kernel. I do not think I want to call system calls as "C API", it's more assembly API or machine code API, and there is C API built around it.

Is that Linux C API available for programmers or is the glibc the lowest we can go?

Let's say the "lowest" you can go in C on Linux is to call syscall().

What do other higher-level frameworks use?

It is specific to that specific "framework". Usually 99.9% of the time any program written in C uses the C standard library available on that system. The build process of that specific application chooses what C standard library to use, and docker shows that applications using multiple C standard libraries can coexist on one system.

.NET, Java, Python,

Python is written in C, for Java see In which language are the Java compiler and JVM written? , I know nothing about .NET .

Do they use glibc APIs or do they directly talk to the Kernel?

If they were compiled against glibc, then they use glibc to communicate with the kernel. But on Alpine, programs use musl.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111