I’m writing a simple shell as an OS course assignment, I need to search in the PATH to find the program user typed in, once I find the right directory, I malloc a piece of memory just enough to hold the directory name plus the program name, and I pass it as the first argument to execv().
I could have statically allocated 100 characters or so, but having a limit makes me feel uncomfortable. So when execv() executes, is the heap cleaned up or is that piece of memory lost?
It’s maybe not a lot of memory but I’m just curious.
When you
exec(), the entire process is (a) ended, so all resources including dynamic memory and some fd’s as below, are reclaimed by the operating system, and (b) replaced: code, data, threads, …Re file descriptors, from
"man execve":