Alain Magloire <alain@qnx.com> wrote:
p.s.: This may look obvious, but sometime people ask me this.
Yes memory(and all resources) is return back to the system when the
process exit.
Actually, that isn’t quite true. Resources that are asssociated with
a name may (will) endure past process death. For example, if you do
a shm_open(…, O_CREAT) then ftruncate() to allocate a shared memory area,
that memory will not be released until the name that is passed to shm_open()
has been unlinked. Similarly for open(), sem_open(), mqueue_open(), etc.
The rules for when something are released are, generally:
If associated with a name, it will be released after the name has been
unlinked and all references to the object have been closed/released.
(e.g. for shared memory when all fds to the object are closed and all
mappings have been unmapped.)
An object that is associated with memory, essentially most if not all of
the synchronisation objects such as unnammed semaphores, mutexes, condition
variables, etc will be released when the memory they are in is released.
Other resources, including normal process memory, fds, mappings, irq handlers,
pids, chids, coids, etc (generally anything that has a numeric identifier)
will be released/freed when a process exits. Since memory is released,
this also means that in most cases semaphores, mutexes, etc get automatically
released when a process exits, since they are usually in process local
memory.
-David
QNX Training Services
dagibbs@qnx.com