Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relation between Linux kernel and GNU C library?

We know that Linux kernel is written in C. But does it also call standard C functions like malloc() or extra functions like mmap() which are provided by GNU C library (glibc)? In that case, it's strange, because direct low-level interaction with hardware, e.g. memory management, is supposed to be almost always the task of a kernel. So, which is dependent on the other? Which is more fundamental/low-level?

like image 436
apadana Avatar asked Jan 14 '20 15:01

apadana


1 Answers

We know that Linux kernel is written in C. But does it also call standard C functions like malloc()

No. However, the kernel defines similar functions like kmalloc. Note this is not part of a library; it's part of the kernel itself.

or extra functions like mmap()

Not mmap, but there are a lot of memory management functions in the kernel.

which are provided by GNU C library (glibc)?

Definitely not. The kernel does not use glibc ever.

So, which is dependent on the other?

Some parts of glibc depends on the kernel. Other parts (like strcpy) have nothing to do with the kernel and don't depend on it. The kernel never depends on glibc. You can run programs on Linux that use a different libc (like "musl") or that don't use a libc at all.

like image 172
user253751 Avatar answered Sep 22 '22 04:09

user253751