:: [DNG] [katolaz@freaknet.org: Re: Do…
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: KatolaZ
Ημερομηνία:  
Προς: dng
Αντικείμενο: [DNG] [katolaz@freaknet.org: Re: Doing away with multi-threading in my project (netman)]
On Sat, Sep 05, 2015 at 08:54:25PM +0100, Edward Bartolo wrote:
> Correction:
>
> Sorry, but it looks there is only a very subtle difference between the
> two. The only difference I see, is that, since in the case of execl,
> the parent effectively is replaced, i.e. dies, the child process is awarded its
> parent PID. This is not the case when a parent process creates a child
> process and exits immediately, as the child will have a different PID.
>
>
>


Maybe I am stating the obvious again, but the only way to create a
child process is by calling "fork()". Such a call will effectively
clone the current process into a child process. This means that the
child inherits (almost) *everything* from the parent, including its
progam pages (the code). This is why, usually, the first thing a child
process does is to call to one of the functions in the exec?* family
(execv, execl, or one of the many existing variants), which
effectively loads *another* program in the program page of the current
process (in this case, the child process), and starts executing it.

When a process dies, it becomes a "zombie" and a SIGCHLD signal is
delivered to its parent. The correct way of managing this *normal*
behaviour is for the parent to set a signal handler for SIGCHLD which
calls waitpid (I sent a reference about this in a previous
email). This is what is meant by "reaping" children. If this is not
done, the zombie process will hang around forever (almost, see below).

If the parent of a process dies before the process itself, the
"orphaned" process is assigned a new parent, which is the process with
PID 1 (init). This means that init will then take care of all the
orphaned children of the dead process, becoming their parent, and, as
any good parent, will receive the SIGCHLD from any of those processes
when they die. On top of that, init will also receive a SIGCHLD for
any of those orphaned process which were zombie before "adoption", and
will take care of those signals properly (i.e., by calling waitpid in
the handler of SIGCHLD it had set beforehand).


To the best of my knowledge, the scenario you where suggesting in a
previous email (children processes which are adopted by their
grandfather) is not feasible, with the only incidental exception in
which their grandparent is PID 1 itself (init).

My2Cents

KatolaZ


--
[ Enzo Nicosia aka KatolaZ --- GLUG Catania -- Freaknet Medialab ]
[ me [at] katolaz.homeunix.net -- http://katolaz.homeunix.net -- ]
[ GNU/Linux User:#325780/ICQ UIN: #258332181/GPG key ID 0B5F062F ]
[ Fingerprint: 8E59 D6AA 445E FDB4 A153 3D5A 5F20 B3AE 0B5F 062F ]