Link to home
Start Free TrialLog in
Avatar of Ignatz
Ignatz

asked on

malloc() and fork()

When I call fork(), are all my dynamic memory pointers copied, and pointing to new memory addresses? Is this chunk of code correct? Please explain. Thank You.

int fork_func(void)
{
   char *p;

   p = (char *)malloc(100);
   if (!fork()) {
      /** some processing **/
      free((void *)p);
   }
   free((void *)p);
   return 0;
}
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ignatz
Ignatz

ASKER

Thanks, I am currently calling exit(0) after free() in child process, but I forgot to put that in my sample code.