C programming question

David Nicol nicold at umkc.edu
Fri Jan 4 18:17:25 CST 2002


Jeremy Fowler wrote:

> Does anyone know how fork() handles dynamically assigned memory (malloc) that
> existed _before_ the call to fork()? Does the new child process get a complete
> copy of the memory allocated or just a copy of the address of the original
> allocated memory?

shared memory segements are the only ones that exist independently
of processes.  The parent needs to clean up after the fork, but exec will
clobber all the memory (i may be mistaken -- play with it and see)

The child process gets a complete copy of the parent's memory.  Implementing
this as a copy-on-write page table would be a very slick manouver but 
the semantics from a programmer perspective would be identical.

Outside of shared memory segments, which might be able to persist without
a process using them (not sure) you don't have to worry about memory clean up
if the process is going to exit, the kernel will recycle it all.

-- 
                David L Nicol, humble system administrator (816) 235 1187
                                                 After several years, ...




More information about the Kclug mailing list