> Iam very much confused by this . I may have missed something
> please correct me if iam wrong .
> > If a child process is using a resource that has
> > been created in the parent and is an automatic (allocated on the stack),
> > static or global (allocated in its data segment), then that portion cannot
> > be returned to the free pool to be overwritten by another process.
> After the fork the child and parent run in their own address spaces and
> the automatic and global data in one cannot affect the other .so any
> variable created in the parent should not matter at all in the child .
Not true! When you fork() a child process, it too inherits any open file
descriptors (and associated pending I/O), process permissions, file creation
masks and resource limits, environment, signal handlers (including their
function addresses), all attached shared memory segments, memory mappings,
the controlling terminal, and copies of any global and static variables
(however they may be pointers to common shared data segments). (see fork(2))
There are a number of calls you can make to detach the child process from
these resources, but until so, they need to remain. Therefore, if the
parent has the resource, its process cannot be removed until all of its
resources are freed.
> My understanding of a defunt process and its cause is this
> When a child calls exit , If its parent is running and has not called
> wait to accept the exit statusof the child , the child becomes a defunct
Wrong! The child silently exits. If the child is killed (from signal())
and it has pending I/O or a resource shared with another process, then it
will remain a zombie until the other process or I/O device driver finishes
with the resource. In this case, a parent's wait() call will return, but
the child will become a zombie.
> If the parent exits before the child . init takes over as the parent
> .and calls wait so the child does not become a defunct process in this
> case .
> But the strange thing is sometimes i see a defunct process with its
> parent as init .
The parent will be removed from the process table only when all of its
resources are able to be freed (the resource attach counters reduced to
zero -- they are incremented when a call to fork() is made). If a parent's
resources are no longer being addressed by the child, they can be returned
to their respective free pools, and the child is then adopted by the init
process (init becomes its parent).
Scott G. Hall
GTE Government Systems
North Carolina Systems Center