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.
4096(from/usr/src/linux-2.4.20-8/include/linux/limits.h,#define PATH_MAX 4096 /* # chars in a path name including nul */). So you should be includinglimits.hand making your bufferPATH_MAXcharacters in length.