Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens with memory usage after exec*()

Tags:

c

linux

C parent program does some processing and allocates memory, then calls execvp(). What will happen with all the allocated but not freed memory? Is it automatically freed or stays as a garbage?

like image 330
askonecki Avatar asked Sep 01 '10 11:09

askonecki


People also ask

Does Execvp free memory?

Specifically, if you allocate memory in a process before an exec() -type routine (e.g., execvp() in your case) is called, all of the memory associated with the original executable is released.

What does Execve function do?

The execve function is most commonly used to overlay a process image that has been created by a call to the fork function. is the filename of the file that contains the executable image of the new process. is a pointer to an array of pointers to null-terminated character strings.


1 Answers

exec*() replaced the memory of the old process completely with the new program. This includes all allocated memory, so there is no garbage staying behind. But note that other resources like file descriptors are not automatically freed or closed.

like image 109
Sven Avatar answered Sep 22 '22 07:09

Sven