Pregunta

We all know that when a C program executes, there are lots of plumbing jobs done by the OS under the hood, before entering main, such as allocating a stack, initiating some resources, loading the binary,etc.

So intuitively I regard these jobs part of the OS. However, the fact is that all these jobs are in an important module called CRT(C runtime library), like glibc in linux, or msvcrt.dll in Windows. I wanna know its whereforce.

¿Fue útil?

Solución

These routine process creation task are done irrespective of whether its for a C program or a Java or a PHP program.

Plus it is not necessary for programs written in languages other than C(or even C) to use the C standard library. Hence we cannot put all these routine tasks in a C standard library.

For e.g., in case of Linux systems, the "program loader" and "dynamic linker" are not part of the gnu c library. They are the part of separate "binutils" package.

This link though a bit dated will give you a fair amount of information on the journey of writing a program to a running process. It uses gcc/Linux but major tasks are the similar on other platforms.

EDIT /* THE DYNAMIC LINKER IS A PART OF GLIBC...THANKS TO employedrussian */

Otros consejos

It's important to understand why there's separation of user mode and kernel mode exists in the operating system. In simple words it improves the system stability. C-Runtime library is just a library which make use of operating system services. It is loaded along with the process. Mostly our programs are user mode programs (unlike drivers and other OS core services). The allocation of resources is done by other operating system services and these libraries are safe way to access them!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top