Well, I just copied the code over from the question
to illustrate, but ...
- $SIG{CHLD} = sub {wait()};
This ensures
proper cleanup of child resources after child terminates.
"When a process exits, its parent is sent a CHLD signal
by the kernel and the process becomes a zombie until
the parent calls wait or waitpid.
If you start another process in Perl using anything except fork, Perl takes care of reaping your zombied children, but if you use a raw fork, you're expected to clean up after yourself." (from Camel, 3rd ed.).
I don't know really if this is needed on Win32, but
it is supported, since "wait() and waitpid() can be passed a pseudo-process ID returned by fork(). These calls will properly wait for the termination of the pseudo-process and return its status." (from ActiveState Perl docs).
- The else clause is the main server process.
It blocks reading one line from STDIN and sends that to the newly forked socket connection.
This is probably not the best example code for writing
servers and clients. Have a look at the Perl Cookbook,
chapter 17.
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|