[SunHELP] parent process & child process?

Ben Ricker bricker at wellinx.com
Thu Apr 25 15:36:11 CDT 2002


On Thu, 2002-04-25 at 15:13, Solaris Neophyte wrote:
> I don't follow what these are... 
> 
> this is what my text says...
> 
> "When a process is started, a duplicate of that process is created.  This new
> process is called the child and the process that created it is called the
> parent.  The child process then replaces the copy for the code the parent
> process created with the code the child process is supposted to execute."
> 
> The last sentance confuses me the most.  Actually the entire thing confsues me.
>  Why is a child process started anyways? 

That is the way the program is written. Most daemons work that way. Use
Apache 1.3 as an example: it starts a process as root which then spawns
child processes which are run under a different UID. Basically, the
reasoning is that the daemon listens on the port for connections and
when a request is made for a port it is listening to, it spawns the
child and then lets the child handle the connection.

> Why does the parent process spawn a
> child process in the first place? 

Because it would not be as stable. If the parent Apache process would
die because of a segfaulting thread, the whole web server would come
down. With the spawning child process method, only the child dies.

> And what's all this code copy stuff all
> about?

Basically, this is an elucidation of "spawning a child process". The
child executes the code it is meant to execute (say, negotiating an HTML
request) as well as executing the code inherited from the parent. This
is a quasi object-oriented notion.
 
> The next paragraph states...
> 
> "While the command is executing, the shell waits until the child process has
> completed.  After is completes, the parent process terminates the child
> process, and a prompt is displated, ready for a new command"
> 
> Why does this happen?

Well, you have to stop the child when it is done, or you would get a
leak: each subsequent would execute another child process which never
gets closed, thereby slowly filling up RAM.

>  I guess it goes back to my confusion about why the child
> process is created in the first place.

See above: something must be listening for connections> This is the
parent. If it binds up that port and does not spawn a child, the next
connection would have to wait for the previous connection to close. it
allows multiple connections to the same listening port, while providing
better stability.

One may want to use a multi-threaded approach (like Apache 2.x) where
instead of spawning a child process, a thread within the process is
opened which handles the connection.

Check out
http://apachetoday.com/news_story.php3?ltsn=2000-05-28-004-01-PS
for an explanation of both methods of handling requests (threaded vs
preforked processing).

Ben Ricker
Web Security System Administrator
Wellinx.com

> Yahoo! Games - play chess, backgammon, pool and more
> http://games.yahoo.com/
> _______________________________________________
> SunHELP maillist  -  SunHELP at sunhelp.org
> http://www.sunhelp.org/mailman/listinfo/sunhelp



More information about the SunHELP mailing list