This is for a school project, and I am looking for guidence on going about freeing memory of a parameter to an exec call. This isn't the point of the project, just a detail I am stuck on planning out. Its a license manager, only letting a specified number of process run at a time.
It gets a line of text (char*) that I parse into an argv type array, char* arr. arr is the command, and the rest of it are parameters.
The array is made using malloc and calloc, so its memory that needs to be free'ed at some point. Code written for previous project, what we have to use.
After I get this array arr, I call fork, then have the child call execvp(arr, arr). At that point, execution passes to the command in arr.
I am wondering how I could go about making sure the memory is free'ed when the command is finished, short of a whole other control structure just tracking these arrays, unless I'm missing an STL that will do what I need.
Only thing I have found so far is atexit(), but will it still work after the exec? I'm not at a point to test this myself yet, wondering if others have played with it.
Anyone have pointers on how I could handle this, if atexit isn't the way?