Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Recently I found this in a powerpoint presentation:

When a program is compiled and linked, the linker inserts some extra code in the program. It is this code that calls the main function about the same way a user calls "lower functions".

The extra code has two functionalities:

  • make sure that the C program runs in the right environment
  • cleanup after succesfull termination

Prior to that I thought that cleanup was kernel's job. What is the right story?

share|improve this question

1 Answer 1

Both the kernel and the C runtime do some of the work.

Some of the things that the C runtime does which the kernel doesn't do: it runs handlers previously registered with atexit() and it arranges for the integer return value from main() to be returned to the system as if with exit().

Of course in the end the kernel will reap all resources (files, memory) regardless of what userland does or doesn't do.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.