home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 July / AMIGA_1996_7.BIN / ausgabe_7_96 / pd-programmierung / perl5_002bin.lha / man / catp / perlipc.0 < prev    next >
Text File  |  1996-03-02  |  102KB  |  1,255 lines

  1.  
  2.  
  3.  
  4. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  5.  
  6.  
  7. NNNNAAAAMMMMEEEE
  8.        perlipc - Perl interprocess communication (signals, fifos,
  9.        pipes, safe subprocceses, sockets, and semaphores)
  10.  
  11. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.        The basic IPC facilities of Perl are built out of the good
  13.        old Unix signals, named pipes, pipe opens, the Berkeley
  14.        socket routines, and SysV IPC calls.  Each is used in
  15.        slightly different situations.
  16.  
  17. SSSSiiiiggggnnnnaaaallllssss
  18.        Perl uses a simple signal handling model: the %%%%SSSSIIIIGGGG hash
  19.        contains names or references of user-installed signal
  20.        handlers.  These handlers will be called with an argument
  21.        which is the name of the signal that triggered it.  A
  22.        signal may be generated intentionally from a particular
  23.        keyboard sequence like control-C or control-Z, sent to you
  24.        from an another process, or triggered automatically by the
  25.        kernel when special events transpire, like a child process
  26.        exiting, your process running out of stack space, or
  27.        hitting file size limit.
  28.  
  29.        For example, to trap an interrupt signal, set up a handler
  30.        like this.  Notice how all we do is set with a global
  31.        variable and then raise an exception.  That's because on
  32.        most systems libraries are not re-entrant, so calling any
  33.        _p_r_i_n_t_(_) functions (or even anything that needs to
  34.        _m_a_l_l_o_c(3) more memory) could in theory trigger a memory
  35.        fault and subsequent core dump.
  36.  
  37.            ssssuuuubbbb ccccaaaattttcccchhhh____zzzzaaaapppp {{{{
  38.                mmmmyyyy $$$$ssssiiiiggggnnnnaaaammmmeeee ==== sssshhhhiiiifffftttt;;;;
  39.                $$$$sssshhhhuuuucccckkkkssss++++++++;;;;
  40.                ddddiiiieeee """"SSSSoooommmmeeeebbbbooooddddyyyy sssseeeennnntttt mmmmeeee aaaa SSSSIIIIGGGG$$$$ssssiiiiggggnnnnaaaammmmeeee"""";;;;
  41.            }}}}
  42.            $$$$SSSSIIIIGGGG{{{{IIIINNNNTTTT}}}} ==== ''''ccccaaaattttcccchhhh____zzzzaaaapppp'''';;;;  #### ccccoooouuuulllldddd ffffaaaaiiiillll iiiinnnn mmmmoooodddduuuulllleeeessss
  43.            $$$$SSSSIIIIGGGG{{{{IIIINNNNTTTT}}}} ==== \\\\&&&&ccccaaaattttcccchhhh____zzzzaaaapppp;;;;  #### bbbbeeeesssstttt ssssttttrrrraaaatttteeeeggggyyyy
  44.  
  45.        The names of the signals are the ones listed out by kkkkiiiillllllll
  46.        ----llll on your system, or you can retrieve them from the
  47.        Config module.  Set up an @@@@ssssiiiiggggnnnnaaaammmmeeee list indexed by number
  48.        to get the name and a %%%%ssssiiiiggggnnnnoooo table indexed by name to get
  49.        the number:
  50.  
  51.            uuuusssseeee CCCCoooonnnnffffiiiigggg;;;;
  52.            ddddeeeeffffiiiinnnneeeedddd $$$$CCCCoooonnnnffffiiiigggg{{{{ssssiiiigggg____nnnnaaaammmmeeee}}}} |||||||| ddddiiiieeee """"NNNNoooo ssssiiiiggggssss????"""";;;;
  53.            ffffoooorrrreeeeaaaacccchhhh $$$$nnnnaaaammmmeeee ((((sssspppplllliiiitttt(((('''' '''',,,, $$$$CCCCoooonnnnffffiiiigggg{{{{ssssiiiigggg____nnnnaaaammmmeeee}}}})))))))) {{{{
  54.                $$$$ssssiiiiggggnnnnoooo{{{{$$$$nnnnaaaammmmeeee}}}} ==== $$$$iiii;;;;
  55.                $$$$ssssiiiiggggnnnnaaaammmmeeee[[[[$$$$iiii]]]] ==== $$$$nnnnaaaammmmeeee;;;;
  56.                $$$$iiii++++++++;;;;
  57.            }}}}
  58.  
  59.        So to check whether signal 17 and SIGALRM were the same,
  60.        just do this:
  61.  
  62.  
  63.  
  64. 30/Jan/96                perl 5.002 with                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  71.  
  72.  
  73.            pppprrrriiiinnnntttt """"ssssiiiiggggnnnnaaaallll ####11117777 ==== $$$$ssssiiiiggggnnnnaaaammmmeeee[[[[11117777]]]]\\\\nnnn"""";;;;
  74.            iiiiffff (((($$$$ssssiiiiggggnnnnoooo{{{{AAAALLLLRRRRMMMM}}}})))) {{{{
  75.                pppprrrriiiinnnntttt """"SSSSIIIIGGGGAAAALLLLRRRRMMMM iiiissss $$$$ssssiiiiggggnnnnoooo{{{{AAAALLLLRRRRMMMM}}}}\\\\nnnn"""";;;;
  76.            }}}}
  77.  
  78.        You may also choose to assign the strings ''''IIIIGGGGNNNNOOOORRRREEEE'''' or
  79.        ''''DDDDEEEEFFFFAAAAUUUULLLLTTTT'''' as the handler, in which case Perl will try to
  80.        discard the signal or do the default thing.  Some signals
  81.        can be neither trapped nor ignored, such as the KILL and
  82.        STOP (but not the TSTP) signals.  One strategy for
  83.        temporarily ignoring signals is to use a _l_o_c_a_l_(_)
  84.        statement, which will be automatically restored once your
  85.        block is exited.  (Remember that _l_o_c_a_l_(_) values are
  86.        "inherited" by functions called from within that block.)
  87.  
  88.            ssssuuuubbbb pppprrrreeeecccciiiioooouuuussss {{{{
  89.                llllooooccccaaaallll $$$$SSSSIIIIGGGG{{{{IIIINNNNTTTT}}}} ==== ''''IIIIGGGGNNNNOOOORRRREEEE'''';;;;
  90.                &&&&mmmmoooorrrreeee____ffffuuuunnnnccccttttiiiioooonnnnssss;;;;
  91.            }}}}
  92.            ssssuuuubbbb mmmmoooorrrreeee____ffffuuuunnnnccccttttiiiioooonnnnssss {{{{
  93.                #### iiiinnnntttteeeerrrrrrrruuuuppppttttssss ssssttttiiiillllllll iiiiggggnnnnoooorrrreeeedddd,,,, ffffoooorrrr nnnnoooowwww............
  94.            }}}}
  95.  
  96.        Sending a signal to a negative process ID means that you
  97.        send the signal to the entire Unix process-group.  This
  98.        code send a hang-up signal to all processes in the current
  99.        process group _e_x_c_e_p_t _f_o_r the current process itself:
  100.  
  101.            {{{{
  102.                llllooooccccaaaallll $$$$SSSSIIIIGGGG{{{{HHHHUUUUPPPP}}}} ==== ''''IIIIGGGGNNNNOOOORRRREEEE'''';;;;
  103.                kkkkiiiillllllll HHHHUUUUPPPP ====>>>> ----$$$$$$$$;;;;
  104.                #### ssssnnnnaaaazzzzzzzzyyyy wwwwrrrriiiittttiiiinnnngggg ooooffff:::: kkkkiiiillllllll((((''''HHHHUUUUPPPP'''',,,, ----$$$$$$$$))))
  105.            }}}}
  106.  
  107.        Another interesting signal to send is signal number zero.
  108.        This doesn't actually affect another process, but instead
  109.        checks whether it's alive or has changed its UID.
  110.  
  111.            uuuunnnnlllleeeessssssss ((((kkkkiiiillllllll 0000 ====>>>> $$$$kkkkiiiidddd____ppppiiiidddd)))) {{{{
  112.                wwwwaaaarrrrnnnn """"ssssoooommmmeeeetttthhhhiiiinnnngggg wwwwiiiicccckkkkeeeedddd hhhhaaaappppppppeeeennnneeeedddd ttttoooo $$$$kkkkiiiidddd____ppppiiiidddd"""";;;;
  113.            }}}}
  114.  
  115.        You might also want to employ anonymous functions for
  116.        simple signal handlers:
  117.  
  118.            $$$$SSSSIIIIGGGG{{{{IIIINNNNTTTT}}}} ==== ssssuuuubbbb {{{{ ddddiiiieeee """"\\\\nnnnOOOOuuuuttttttttaaaa hhhheeeerrrreeee!!!!\\\\nnnn"""" }}}};;;;
  119.  
  120.        But that will be problematic for the more complicated
  121.        handlers that need to re-install themselves.  Because
  122.        Perl's signal mechanism is currently based on the
  123.        _s_i_g_n_a_l(3) function from the C library, you may somtimes be
  124.        so misfortunate as to run on systems where that function
  125.        is "broken", that is, it behaves in the old unreliable
  126.        SysV way rather than the newer, more reasonable BSD and
  127.  
  128.  
  129.  
  130. 30/Jan/96                perl 5.002 with                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  137.  
  138.  
  139.        POSIX fashion.  So you'll see defensive people writing
  140.        signal handlers like this:
  141.  
  142.            ssssuuuubbbb RRRREEEEAAAAPPPPEEEERRRR {{{{
  143.                $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;  #### llllooooaaaatttthhhheeee ssssyyyyssssVVVV
  144.                $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== wwwwaaaaiiiitttt;;;;
  145.            }}}}
  146.            $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;
  147.            #### nnnnoooowwww ddddoooo ssssoooommmmeeeetttthhhhiiiinnnngggg tttthhhhaaaatttt ffffoooorrrrkkkkssss............
  148.  
  149.        or even the more elaborate:
  150.  
  151.            uuuusssseeee PPPPOOOOSSSSIIIIXXXX """"wwwwaaaaiiiitttt____hhhh"""";;;;
  152.            ssssuuuubbbb RRRREEEEAAAAPPPPEEEERRRR {{{{
  153.                mmmmyyyy $$$$cccchhhhiiiilllldddd;;;;
  154.                $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;  #### llllooooaaaatttthhhheeee ssssyyyyssssVVVV
  155.                wwwwhhhhiiiilllleeee (((($$$$cccchhhhiiiilllldddd ==== wwwwaaaaiiiittttppppiiiidddd((((----1111,,,,WWWWNNNNOOOOHHHHAAAANNNNGGGG)))))))) {{{{
  156.                    $$$$KKKKiiiidddd____SSSSttttaaaattttuuuussss{{{{$$$$cccchhhhiiiilllldddd}}}} ==== $$$$????;;;;
  157.                }}}}
  158.            }}}}
  159.            $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;
  160.            #### ddddoooo ssssoooommmmeeeetttthhhhiiiinnnngggg tttthhhhaaaatttt ffffoooorrrrkkkkssss............
  161.  
  162.        Signal handling is also used for timeouts in Unix,   While
  163.        safely protected within an eeeevvvvaaaallll{{{{}}}} block, you set a signal
  164.        handler to trap alarm signals and then schedule to have
  165.        one delivered to you in some number of seconds.  Then try
  166.        your blocking operation, clearing the alarm when it's done
  167.        but not before you've exited your eeeevvvvaaaallll{{{{}}}} block.  If it
  168.        goes off, you'll use _d_i_e_(_) to jump out of the block, much
  169.        as you might using _l_o_n_g_j_m_p_(_) or _t_h_r_o_w_(_) in other
  170.        languages.
  171.  
  172.        Here's an example:
  173.  
  174.            eeeevvvvaaaallll {{{{
  175.                llllooooccccaaaallll $$$$SSSSIIIIGGGG{{{{AAAALLLLRRRRMMMM}}}} ==== ssssuuuubbbb {{{{ ddddiiiieeee """"aaaallllaaaarrrrmmmm cccclllloooocccckkkk rrrreeeessssttttaaaarrrrtttt"""" }}}};;;;
  176.                aaaallllaaaarrrrmmmm 11110000;;;;
  177.                fffflllloooocccckkkk((((FFFFHHHH,,,, 2222))));;;;   #### bbbblllloooocccckkkkiiiinnnngggg wwwwrrrriiiitttteeee lllloooocccckkkk
  178.                aaaallllaaaarrrrmmmm 0000;;;;
  179.            }}}};;;;
  180.            iiiiffff (((($$$$@@@@ aaaannnndddd $$$$@@@@ !!!!~~~~ ////aaaallllaaaarrrrmmmm cccclllloooocccckkkk rrrreeeessssttttaaaarrrrtttt////)))) {{{{ ddddiiiieeee }}}}
  181.  
  182.        For more complex signal handling, you might see the
  183.        standard POSIX module.  Lamentably, this is almost
  184.        entirely undocumented, but the _t_/_l_i_b_/_p_o_s_i_x_._t file from the
  185.        Perl source distribution has some examples in it.
  186.  
  187. NNNNaaaammmmeeeedddd PPPPiiiippppeeeessss
  188.        A named pipe (often referred to as a FIFO) is an old Unix
  189.        IPC mechanism for processes communicating on the same
  190.        machine.  It works just like a regular, connected
  191.        anonymous pipes, except that the processes rendezvous
  192.        using a filename and don't have to be related.
  193.  
  194.  
  195.  
  196. 30/Jan/96                perl 5.002 with                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  203.  
  204.  
  205.        To create a named pipe, use the Unix command _m_k_n_o_d(1) or
  206.        on some systems, _m_k_f_i_f_o(1).  These may not be in your
  207.        normal path.
  208.  
  209.            #### ssssyyyysssstttteeeemmmm rrrreeeettttuuuurrrrnnnn vvvvaaaallll iiiissss bbbbaaaacccckkkkwwwwaaaarrrrddddssss,,,, ssssoooo &&&&&&&& nnnnooootttt ||||||||
  210.            ####
  211.            $$$$EEEENNNNVVVV{{{{PPPPAAAATTTTHHHH}}}} ....==== """"::::////eeeettttcccc::::////uuuussssrrrr////eeeettttcccc"""";;;;
  212.            iiiiffff  ((((      ssssyyyysssstttteeeemmmm((((''''mmmmkkkknnnnoooodddd'''',,,,  $$$$ppppaaaatttthhhh,,,, ''''pppp''''))))
  213.                    &&&&&&&& ssssyyyysssstttteeeemmmm((((''''mmmmkkkkffffiiiiffffoooo'''',,,, $$$$ppppaaaatttthhhh)))) ))))
  214.            {{{{
  215.                ddddiiiieeee """"mmmmkkkk{{{{nnnnoooodddd,,,,ffffiiiiffffoooo}}}} $$$$ppppaaaatttthhhh ffffaaaaiiiilllleeeedddd;;;;
  216.            }}}}
  217.  
  218.        A fifo is convenient when you want to connect a process to
  219.        an unrelated one.  When you open a fifo, the program will
  220.        block until there's something on the other end.
  221.  
  222.        For example, let's say you'd like to have your _._s_i_g_n_a_t_u_r_e
  223.        file be a named pipe that has a Perl program on the other
  224.        end.  Now every time any program (like a mailer,
  225.        newsreader, finger program, etc.) tries to read from that
  226.        file, the reading program will block and your program will
  227.        supply the the new signature.  We'll use the pipe-checking
  228.        file test ----pppp to find out whether anyone (or anything) has
  229.        accidentally removed our fifo.
  230.  
  231.            cccchhhhddddiiiirrrr;;;; #### ggggoooo hhhhoooommmmeeee
  232.            $$$$FFFFIIIIFFFFOOOO ==== ''''....ssssiiiiggggnnnnaaaattttuuuurrrreeee'''';;;;
  233.            $$$$EEEENNNNVVVV{{{{PPPPAAAATTTTHHHH}}}} ....==== """"::::////eeeettttcccc::::////uuuussssrrrr////ggggaaaammmmeeeessss"""";;;;
  234.  
  235.            wwwwhhhhiiiilllleeee ((((1111)))) {{{{
  236.                uuuunnnnlllleeeessssssss ((((----pppp $$$$FFFFIIIIFFFFOOOO)))) {{{{
  237.                    uuuunnnnlllliiiinnnnkkkk $$$$FFFFIIIIFFFFOOOO;;;;
  238.                    ssssyyyysssstttteeeemmmm((((''''mmmmkkkknnnnoooodddd'''',,,, $$$$FFFFIIIIFFFFOOOO,,,, ''''pppp''''))))
  239.                        &&&&&&&& ddddiiiieeee """"ccccaaaannnn''''tttt mmmmkkkknnnnoooodddd $$$$FFFFIIIIFFFFOOOO:::: $$$$!!!!"""";;;;
  240.                }}}}
  241.  
  242.                #### nnnneeeexxxxtttt lllliiiinnnneeee bbbblllloooocccckkkkssss uuuunnnnttttiiiillll tttthhhheeeerrrreeee''''ssss aaaa rrrreeeeaaaaddddeeeerrrr
  243.                ooooppppeeeennnn ((((FFFFIIIIFFFFOOOO,,,, """">>>> $$$$FFFFIIIIFFFFOOOO"""")))) |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt wwwwrrrriiiitttteeee $$$$FFFFIIIIFFFFOOOO:::: $$$$!!!!"""";;;;
  244.                pppprrrriiiinnnntttt FFFFIIIIFFFFOOOO """"JJJJoooohhhhnnnn SSSSmmmmiiiitttthhhh ((((ssssmmmmiiiitttthhhh\\\\@@@@hhhhoooosssstttt....oooorrrrgggg))))\\\\nnnn"""",,,, ````ffffoooorrrrttttuuuunnnneeee ----ssss````;;;;
  245.                cccclllloooosssseeee FFFFIIIIFFFFOOOO;;;;
  246.                sssslllleeeeeeeepppp 2222;;;;    #### ttttoooo aaaavvvvooooiiiidddd dddduuuupppp ssssiiiiggggssss
  247.            }}}}
  248.  
  249.  
  250. UUUUssssiiiinnnngggg _o_p_e_n_(_) for IPC
  251.        Perl's basic _o_p_e_n_(_) statement can also be used for
  252.        unidirectional interprocess communication by either
  253.        appending or prepending a pipe symbol to the second
  254.        argument to _o_p_e_n_(_).  Here's how to start something up a
  255.        child process you intend to write to:
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. 30/Jan/96                perl 5.002 with                        4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  269.  
  270.  
  271.            ooooppppeeeennnn((((SSSSPPPPOOOOOOOOLLLLEEEERRRR,,,, """"|||| ccccaaaatttt ----vvvv |||| llllpppprrrr ----hhhh 2222>>>>////ddddeeeevvvv////nnnnuuuullllllll""""))))
  272.                            |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt ffffoooorrrrkkkk:::: $$$$!!!!"""";;;;
  273.            llllooooccccaaaallll $$$$SSSSIIIIGGGG{{{{PPPPIIIIPPPPEEEE}}}} ==== ssssuuuubbbb {{{{ ddddiiiieeee """"ssssppppoooooooolllleeeerrrr ppppiiiippppeeee bbbbrrrrooookkkkeeee"""" }}}};;;;
  274.            pppprrrriiiinnnntttt SSSSPPPPOOOOOOOOLLLLEEEERRRR """"ssssttttuuuuffffffff\\\\nnnn"""";;;;
  275.            cccclllloooosssseeee SSSSPPPPOOOOOOOOLLLLEEEERRRR |||||||| ddddiiiieeee """"bbbbaaaadddd ssssppppoooooooollll:::: $$$$!!!! $$$$????"""";;;;
  276.  
  277.        And here's how to start up a child process you intend to
  278.        read from:
  279.  
  280.            ooooppppeeeennnn((((SSSSTTTTAAAATTTTUUUUSSSS,,,, """"nnnneeeettttssssttttaaaatttt ----aaaannnn 2222>>>>&&&&1111 ||||""""))))
  281.                            |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt ffffoooorrrrkkkk:::: $$$$!!!!"""";;;;
  282.            wwwwhhhhiiiilllleeee ((((<<<<SSSSTTTTAAAATTTTUUUUSSSS>>>>)))) {{{{
  283.                nnnneeeexxxxtttt iiiiffff ////^^^^((((ttttccccpppp||||uuuuddddpppp))))////;;;;
  284.                pppprrrriiiinnnntttt;;;;
  285.            }}}}
  286.            cccclllloooosssseeee SSSSPPPPOOOOOOOOLLLLEEEERRRR |||||||| ddddiiiieeee """"bbbbaaaadddd nnnneeeettttssssttttaaaatttt:::: $$$$!!!! $$$$????"""";;;;
  287.  
  288.        If one can be sure that a particular program is a Perl
  289.        script that is expecting filenames in @@@@AAAARRRRGGGGVVVV, the clever
  290.        programmer can write something like this:
  291.  
  292.            $$$$ pppprrrrooooggggrrrraaaammmm ffff1111 """"ccccmmmmdddd1111||||"""" ---- ffff2222 """"ccccmmmmdddd2222||||"""" ffff3333 <<<< ttttmmmmppppffffiiiilllleeee
  293.  
  294.        and irrespective of which shell it's called from, the Perl
  295.        program will read from the file _f_1, the process _c_m_d_1,
  296.        standard input (_t_m_p_f_i_l_e in this case), the _f_2 file, the
  297.        _c_m_d_2 command, and finally the _f_3 file.  Pretty nifty, eh?
  298.  
  299.        You might notice that you could use backticks for much the
  300.        same effect as opening a pipe for reading:
  301.  
  302.            pppprrrriiiinnnntttt ggggrrrreeeepppp {{{{ !!!!////^^^^((((ttttccccpppp||||uuuuddddpppp))))//// }}}} ````nnnneeeettttssssttttaaaatttt ----aaaannnn 2222>>>>&&&&1111````;;;;
  303.            ddddiiiieeee """"bbbbaaaadddd nnnneeeettttssssttttaaaatttt"""" iiiiffff $$$$????;;;;
  304.  
  305.        While this is true on the surface, it's much more
  306.        efficient to process the file one line or record at a time
  307.        because then you don't have to read the whole thing into
  308.        memory at once. It also gives you finer control of the
  309.        whole process, letting you to kill off the child process
  310.        early if you'd like.
  311.  
  312.        Be careful to check both the _o_p_e_n_(_) and the _c_l_o_s_e_(_) return
  313.        values.  If you're _w_r_i_t_i_n_g to a pipe, you should also trap
  314.        SIGPIPE.  Otherwise, think of what happens when you start
  315.        up a pipe to a command that doesn't exist: the _o_p_e_n_(_) will
  316.        in all likelihood succeed (it only reflects the _f_o_r_k_(_)'s
  317.        success), but then your output will fail--spectacularly.
  318.        Perl can't know whether the command worked because your
  319.        command is actually running in a separate process whose
  320.        _e_x_e_c_(_) might have failed.  Therefore, while readers of
  321.        bogus commands just return a quick end of file, writers to
  322.        bogus command will trigger a signal they'd better be
  323.        prepared to handle.  Consider:
  324.  
  325.  
  326.  
  327.  
  328. 30/Jan/96                perl 5.002 with                        5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  335.  
  336.  
  337.            ooooppppeeeennnn((((FFFFHHHH,,,, """"||||bbbboooogggguuuussss""""))));;;;
  338.            pppprrrriiiinnnntttt FFFFHHHH """"bbbbaaaannnngggg\\\\nnnn"""";;;;
  339.            cccclllloooosssseeee FFFFHHHH;;;;
  340.  
  341.  
  342.        SSSSaaaaffffeeee PPPPiiiippppeeee OOOOppppeeeennnnssss
  343.  
  344.        Another interesting approach to IPC is making your single
  345.        program go multiprocess and communicate between (or even
  346.        amongst) yourselves.  The _o_p_e_n_(_) function will accept a
  347.        file argument of either """"----||||"""" or """"||||----"""" to do a very
  348.        interesting thing: it forks a child connected to the
  349.        filehandle you've opened.  The child is running the same
  350.        program as the parent.  This is useful for safely opening
  351.        a file when running under an assumed UID or GID, for
  352.        example.  If you open a pipe _t_o minus, you can write to
  353.        the filehandle you opened and your kid will find it in his
  354.        STDIN.  If you open a pipe _f_r_o_m minus, you can read from
  355.        the filehandle you opened whatever your kid writes to his
  356.        STDOUT.
  357.  
  358.            uuuusssseeee EEEEnnnngggglllliiiisssshhhh;;;;
  359.            mmmmyyyy $$$$sssslllleeeeeeeepppp____ccccoooouuuunnnntttt ==== 0000;;;;
  360.  
  361.            ddddoooo {{{{
  362.                $$$$ppppiiiidddd ==== ooooppppeeeennnn((((KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE,,,, """"||||----""""))));;;;
  363.                uuuunnnnlllleeeessssssss ((((ddddeeeeffffiiiinnnneeeedddd $$$$ppppiiiidddd)))) {{{{
  364.                    wwwwaaaarrrrnnnn """"ccccaaaannnnnnnnooootttt ffffoooorrrrkkkk:::: $$$$!!!!"""";;;;
  365.                    ddddiiiieeee """"bbbbaaaaiiiilllliiiinnnngggg oooouuuutttt"""" iiiiffff $$$$sssslllleeeeeeeepppp____ccccoooouuuunnnntttt++++++++ >>>> 6666;;;;
  366.                    sssslllleeeeeeeepppp 11110000;;;;
  367.                }}}}
  368.            }}}} uuuunnnnttttiiiillll ddddeeeeffffiiiinnnneeeedddd $$$$ppppiiiidddd;;;;
  369.  
  370.            iiiiffff (((($$$$ppppiiiidddd)))) {{{{  #### ppppaaaarrrreeeennnntttt
  371.                pppprrrriiiinnnntttt KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE @@@@ssssoooommmmeeee____ddddaaaattttaaaa;;;;
  372.                cccclllloooosssseeee((((KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE)))) |||||||| wwwwaaaarrrrnnnn """"kkkkiiiidddd eeeexxxxiiiitttteeeedddd $$$$????"""";;;;
  373.            }}}} eeeellllsssseeee {{{{     #### cccchhhhiiiilllldddd
  374.                (((($$$$EEEEUUUUIIIIDDDD,,,, $$$$EEEEGGGGIIIIDDDD)))) ==== (((($$$$UUUUIIIIDDDD,,,, $$$$GGGGIIIIDDDD))));;;; #### ssssuuuuiiiidddd pppprrrrooooggggssss oooonnnnllllyyyy
  375.                ooooppppeeeennnn ((((FFFFIIIILLLLEEEE,,,, """">>>> ////ssssaaaaffffeeee////ffffiiiilllleeee""""))))
  376.                    |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt ooooppppeeeennnn ////ssssaaaaffffeeee////ffffiiiilllleeee:::: $$$$!!!!"""";;;;
  377.                wwwwhhhhiiiilllleeee ((((<<<<SSSSTTTTDDDDIIIINNNN>>>>)))) {{{{
  378.                    pppprrrriiiinnnntttt FFFFIIIILLLLEEEE;;;; #### cccchhhhiiiilllldddd''''ssss SSSSTTTTDDDDIIIINNNN iiiissss ppppaaaarrrreeeennnntttt''''ssss KKKKIIIIDDDD
  379.                }}}}
  380.                eeeexxxxiiiitttt;;;;  #### ddddoooonnnn''''tttt ffffoooorrrrggggeeeetttt tttthhhhiiiissss
  381.            }}}}
  382.  
  383.        Another common use for this construct is when you need to
  384.        execute something without the shell's interference.  With
  385.        _s_y_s_t_e_m_(_), it's straigh-forward, but you can't use a pipe
  386.        open or backticks safely.  That's because there's no way
  387.        to stop the shell from getting its hands on your
  388.        arguments.   Instead, use lower-level control to call
  389.        _e_x_e_c_(_) directly.
  390.  
  391.  
  392.  
  393.  
  394. 30/Jan/96                perl 5.002 with                        6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  401.  
  402.  
  403.        Here's a safe backtick or pipe open for read:
  404.  
  405.            #### aaaadddddddd eeeerrrrrrrroooorrrr pppprrrroooocccceeeessssssssiiiinnnngggg aaaassss aaaabbbboooovvvveeee
  406.            $$$$ppppiiiidddd ==== ooooppppeeeennnn((((KKKKIIIIDDDD____TTTTOOOO____RRRREEEEAAAADDDD,,,, """"----||||""""))));;;;
  407.  
  408.            iiiiffff (((($$$$ppppiiiidddd)))) {{{{   #### ppppaaaarrrreeeennnntttt
  409.                wwwwhhhhiiiilllleeee ((((<<<<KKKKIIIIDDDD____TTTTOOOO____RRRREEEEAAAADDDD>>>>)))) {{{{
  410.                    #### ddddoooo ssssoooommmmeeeetttthhhhiiiinnnngggg iiiinnnntttteeeerrrreeeessssttttiiiinnnngggg
  411.                }}}}
  412.                cccclllloooosssseeee((((KKKKIIIIDDDD____TTTTOOOO____RRRREEEEAAAADDDD)))) |||||||| wwwwaaaarrrrnnnn """"kkkkiiiidddd eeeexxxxiiiitttteeeedddd $$$$????"""";;;;
  413.  
  414.            }}}} eeeellllsssseeee {{{{      #### cccchhhhiiiilllldddd
  415.                (((($$$$EEEEUUUUIIIIDDDD,,,, $$$$EEEEGGGGIIIIDDDD)))) ==== (((($$$$UUUUIIIIDDDD,,,, $$$$GGGGIIIIDDDD))));;;; #### ssssuuuuiiiidddd oooonnnnllllyyyy
  416.                eeeexxxxeeeecccc(((($$$$pppprrrrooooggggrrrraaaammmm,,,, @@@@ooooppppttttiiiioooonnnnssss,,,, @@@@aaaarrrrggggssss))))
  417.                    |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt eeeexxxxeeeecccc pppprrrrooooggggrrrraaaammmm:::: $$$$!!!!"""";;;;
  418.                #### NNNNOOOOTTTTRRRREEEEAAAACCCCHHHHEEEEDDDD
  419.            }}}}
  420.  
  421.        And here's a safe pipe open for writing:
  422.  
  423.            #### aaaadddddddd eeeerrrrrrrroooorrrr pppprrrroooocccceeeessssssssiiiinnnngggg aaaassss aaaabbbboooovvvveeee
  424.            $$$$ppppiiiidddd ==== ooooppppeeeennnn((((KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE,,,, """"||||----""""))));;;;
  425.            $$$$SSSSIIIIGGGG{{{{AAAALLLLRRRRMMMM}}}} ==== ssssuuuubbbb {{{{ ddddiiiieeee """"wwwwhhhhooooooooppppssss,,,, $$$$pppprrrrooooggggrrrraaaammmm ppppiiiippppeeee bbbbrrrrooookkkkeeee"""" }}}};;;;
  426.  
  427.            iiiiffff (((($$$$ppppiiiidddd)))) {{{{  #### ppppaaaarrrreeeennnntttt
  428.                ffffoooorrrr ((((@@@@ddddaaaattttaaaa)))) {{{{
  429.                    pppprrrriiiinnnntttt KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE;;;;
  430.                }}}}
  431.                cccclllloooosssseeee((((KKKKIIIIDDDD____TTTTOOOO____WWWWRRRRIIIITTTTEEEE)))) |||||||| wwwwaaaarrrrnnnn """"kkkkiiiidddd eeeexxxxiiiitttteeeedddd $$$$????"""";;;;
  432.  
  433.            }}}} eeeellllsssseeee {{{{     #### cccchhhhiiiilllldddd
  434.                (((($$$$EEEEUUUUIIIIDDDD,,,, $$$$EEEEGGGGIIIIDDDD)))) ==== (((($$$$UUUUIIIIDDDD,,,, $$$$GGGGIIIIDDDD))));;;;
  435.                eeeexxxxeeeecccc(((($$$$pppprrrrooooggggrrrraaaammmm,,,, @@@@ooooppppttttiiiioooonnnnssss,,,, @@@@aaaarrrrggggssss))))
  436.                    |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt eeeexxxxeeeecccc pppprrrrooooggggrrrraaaammmm:::: $$$$!!!!"""";;;;
  437.                #### NNNNOOOOTTTTRRRREEEEAAAACCCCHHHHEEEEDDDD
  438.            }}}}
  439.  
  440.        Note that these operations are full Unix forks, which
  441.        means they may not be correctly implemented on alien
  442.        systems.  Additionally, these are not true multithreading.
  443.        If you'd like to learn more about threading, see the
  444.        _m_o_d_u_l_e_s file mentioned below in the the section on _S_E_E
  445.        _A_L_S_O section.
  446.  
  447.        BBBBiiiiddddiiiirrrreeeeccccttttiiiioooonnnnaaaallll CCCCoooommmmmmmmuuuunnnniiiiccccaaaattttiiiioooonnnn
  448.  
  449.        While this works reasonably well for unidirectional
  450.        communication, what about bidirectional communication?
  451.        The obvious thing you'd like to do doesn't actually work:
  452.  
  453.            ooooppppeeeennnn((((PPPPRRRROOOOGGGG____FFFFOOOORRRR____RRRREEEEAAAADDDDIIIINNNNGGGG____AAAANNNNDDDD____WWWWRRRRIIIITTTTIIIINNNNGGGG,,,, """"|||| ssssoooommmmeeee pppprrrrooooggggrrrraaaammmm ||||""""))))
  454.  
  455.        and if you forget to use the ----wwww flag, then you'll miss out
  456.        entirely on the diagnostic message:
  457.  
  458.  
  459.  
  460. 30/Jan/96                perl 5.002 with                        7
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  467.  
  468.  
  469.            CCCCaaaannnn''''tttt ddddoooo bbbbiiiiddddiiiirrrreeeeccccttttiiiioooonnnnaaaallll ppppiiiippppeeee aaaatttt ----eeee lllliiiinnnneeee 1111....
  470.  
  471.        If you really want to, you can use the standard _o_p_e_n_2_(_)
  472.        library function to catch both ends.  There's also an
  473.        _o_p_e_n_3_(_) for tridirectional I/O so you can also catch your
  474.        child's STDERR, but doing so would then require an awkward
  475.        _s_e_l_e_c_t_(_) loop and wouldn't allow you to use normal Perl
  476.        input operations.
  477.  
  478.        If you look at its source, you'll see that _o_p_e_n_2_(_) uses
  479.        low-level primitives like Unix _p_i_p_e_(_) and _e_x_e_c_(_) to create
  480.        all the connections.  While it might have been slightly
  481.        more efficient by using _s_o_c_k_e_t_p_a_i_r_(_), it would have then
  482.        been even less portable than it already is.  The _o_p_e_n_2_(_)
  483.        and _o_p_e_n_3_(_) functions are  unlikely to work anywhere
  484.        except on a Unix system or some other one purporting to be
  485.        POSIX compliant.
  486.  
  487.        Here's an example of using _o_p_e_n_2_(_):
  488.  
  489.            uuuusssseeee FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee;;;;
  490.            uuuusssseeee IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222;;;;
  491.            $$$$ppppiiiidddd ==== ooooppppeeeennnn2222(((( \\\\****RRRReeeeaaaaddddeeeerrrr,,,, \\\\****WWWWrrrriiiitttteeeerrrr,,,, """"ccccaaaatttt ----uuuu ----nnnn"""" ))));;;;
  492.            WWWWrrrriiiitttteeeerrrr---->>>>aaaauuuuttttoooofffflllluuuusssshhhh(((())));;;; #### ddddeeeeffffaaaauuuulllltttt hhhheeeerrrreeee,,,, aaaaccccttttuuuuaaaallllllllyyyy
  493.            pppprrrriiiinnnntttt WWWWrrrriiiitttteeeerrrr """"ssssttttuuuuffffffff\\\\nnnn"""";;;;
  494.            $$$$ggggooootttt ==== <<<<RRRReeeeaaaaddddeeeerrrr>>>>;;;;
  495.  
  496.        The problem with this is that Unix buffering is going to
  497.        really ruin your day.  Even though your WWWWrrrriiiitttteeeerrrr filehandle
  498.        is autoflushed, and the process on the other end will get
  499.        your data in a timely manner, you can't usually do
  500.        anything to force it to actually give it back to you in a
  501.        similarly quick fashion.  In this case, we could, because
  502.        we gave _c_a_t a ----uuuu flag to make it unbuffered.  But very few
  503.        Unix commands are designed to operate over pipes, so this
  504.        seldom works unless you yourself wrote the program on the
  505.        other end of the double-ended pipe.
  506.  
  507.        A solution to this is the non-standard _C_o_m_m_._p_l library.
  508.        It uses pseudo-ttys to make your program behave more
  509.        reasonably:
  510.  
  511.            rrrreeeeqqqquuuuiiiirrrreeee ''''CCCCoooommmmmmmm....ppppllll'''';;;;
  512.            $$$$pppphhhh ==== ooooppppeeeennnn____pppprrrroooocccc((((''''ccccaaaatttt ----nnnn''''))));;;;
  513.            ffffoooorrrr ((((1111........11110000)))) {{{{
  514.                pppprrrriiiinnnntttt $$$$pppphhhh """"aaaa lllliiiinnnneeee\\\\nnnn"""";;;;
  515.                pppprrrriiiinnnntttt """"ggggooootttt bbbbaaaacccckkkk """",,,, ssssccccaaaallllaaaarrrr <<<<$$$$pppphhhh>>>>;;;;
  516.            }}}}
  517.  
  518.        This way you don't have to have control over the source
  519.        code of the program you're using.  The _C_o_m_m library also
  520.        has _e_x_p_e_c_t_(_) and _i_n_t_e_r_a_c_t_(_) functions.  Find the library
  521.        (and hopefully its successor _I_P_C_:_:_C_h_a_t) at your nearest
  522.        CPAN archive as detailed in the the section on _S_E_E _A_L_S_O
  523.  
  524.  
  525.  
  526. 30/Jan/96                perl 5.002 with                        8
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  533.  
  534.  
  535.        section below.
  536.  
  537. SSSSoooocccckkkkeeeettttssss:::: CCCClllliiiieeeennnntttt////SSSSeeeerrrrvvvveeeerrrr CCCCoooommmmmmmmuuuunnnniiiiccccaaaattttiiiioooonnnn
  538.        While not limited to Unix-derived operating systems (e.g.
  539.        WinSock on PCs provides socket support, as do some VMS
  540.        libraries), you may not have sockets on your system, in
  541.        which this section probably isn't going to do you much
  542.        good.  With sockets, you can do both virtual circuits
  543.        (i.e. TCP streams) and datagrams (i.e. UDP packets).  You
  544.        may be able to do even more depending on your system.
  545.  
  546.        The Perl function calls for dealing with sockets have the
  547.        same names as the corresponding system calls in C, but
  548.        their arguments tend to differ for two reasons: first,
  549.        Perl filehandles work differently than C file descriptors.
  550.        Second, Perl already knows the length of its strings, so
  551.        you don't need to pass that information.
  552.  
  553.        One of the major problems with old socket code in Perl was
  554.        that it used hard-coded values for some of the constants,
  555.        which severely hurt portability.  If you ever see code
  556.        that does anything like explicitly setting $$$$AAAAFFFF____IIIINNNNEEEETTTT ==== 2222,
  557.        you know you're in for big trouble:  An immeasurably
  558.        superior approach is to use the SSSSoooocccckkkkeeeetttt module, which more
  559.        reliably grants access to various constants and functions
  560.        you'll need.
  561.  
  562.        IIIInnnntttteeeerrrrnnnneeeetttt TTTTCCCCPPPP CCCClllliiiieeeennnnttttssss aaaannnndddd SSSSeeeerrrrvvvveeeerrrrssss
  563.  
  564.        Use Internet-domain sockets when you want to do client-
  565.        server communication that might extend to machines outside
  566.        of your own system.
  567.  
  568.        Here's a sample TCP client using Internet-domain sockets:
  569.  
  570.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----wwww
  571.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  572.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  573.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  574.            mmmmyyyy (((($$$$rrrreeeemmmmooootttteeee,,,,$$$$ppppoooorrrrtttt,,,, $$$$iiiiaaaaddddddddrrrr,,,, $$$$ppppaaaaddddddddrrrr,,,, $$$$pppprrrroooottttoooo,,,, $$$$lllliiiinnnneeee))));;;;
  575.  
  576.            $$$$rrrreeeemmmmooootttteeee  ==== sssshhhhiiiifffftttt |||||||| ''''llllooooccccaaaallllhhhhoooosssstttt'''';;;;
  577.            $$$$ppppoooorrrrtttt    ==== sssshhhhiiiifffftttt |||||||| 2222333344445555;;;;  #### rrrraaaannnnddddoooommmm ppppoooorrrrtttt
  578.            iiiiffff (((($$$$ppppoooorrrrtttt ====~~~~ ////\\\\DDDD////)))) {{{{ $$$$ppppoooorrrrtttt ==== ggggeeeettttsssseeeerrrrvvvvbbbbyyyynnnnaaaammmmeeee(((($$$$ppppoooorrrrtttt,,,, ''''ttttccccpppp'''')))) }}}}
  579.            ddddiiiieeee """"NNNNoooo ppppoooorrrrtttt"""" uuuunnnnlllleeeessssssss $$$$ppppoooorrrrtttt;;;;
  580.            $$$$iiiiaaaaddddddddrrrr   ==== iiiinnnneeeetttt____aaaattttoooonnnn(((($$$$rrrreeeemmmmooootttteeee))))               |||||||| ddddiiiieeee """"nnnnoooo hhhhoooosssstttt:::: $$$$rrrreeeemmmmooootttteeee"""";;;;
  581.            $$$$ppppaaaaddddddddrrrr   ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppoooorrrrtttt,,,, $$$$iiiiaaaaddddddddrrrr))));;;;
  582.  
  583.            $$$$pppprrrroooottttoooo   ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''ttttccccpppp''''))));;;;
  584.            ssssoooocccckkkkeeeetttt((((SSSSOOOOCCCCKKKK,,,, PPPPFFFF____IIIINNNNEEEETTTT,,,, SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,, $$$$pppprrrroooottttoooo))))  |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  585.            ccccoooonnnnnnnneeeecccctttt((((SSSSOOOOCCCCKKKK,,,, $$$$ppppaaaaddddddddrrrr))))    |||||||| ddddiiiieeee """"ccccoooonnnnnnnneeeecccctttt:::: $$$$!!!!"""";;;;
  586.            wwwwhhhhiiiilllleeee (((($$$$lllliiiinnnneeee ==== <<<<SSSSOOOOCCCCKKKK>>>>)))) {{{{
  587.                pppprrrriiiinnnntttt $$$$lllliiiinnnneeee;;;;
  588.            }}}}
  589.  
  590.  
  591.  
  592. 30/Jan/96                perl 5.002 with                        9
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  599.  
  600.  
  601.            cccclllloooosssseeee ((((SSSSOOOOCCCCKKKK))))            |||||||| ddddiiiieeee """"cccclllloooosssseeee:::: $$$$!!!!"""";;;;
  602.            eeeexxxxiiiitttt;;;;
  603.  
  604.        And here's a corresponding server to go along with it.
  605.        We'll leave the address as INADDR_ANY so that the kernel
  606.        can choose the appropriate interface on multihomed hosts.
  607.        If you want sit on a particular interface (like the
  608.        external side of a gateway or firewall machine), you
  609.        should fill this in with your real address instead.
  610.  
  611.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----TTTTwwww
  612.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  613.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  614.            BBBBEEEEGGGGIIIINNNN {{{{ $$$$EEEENNNNVVVV{{{{PPPPAAAATTTTHHHH}}}} ==== ''''////uuuussssrrrr////uuuuccccbbbb::::////bbbbiiiinnnn'''' }}}}
  615.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  616.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  617.  
  618.            ssssuuuubbbb llllooooggggmmmmssssgggg {{{{ pppprrrriiiinnnntttt """"$$$$0000 $$$$$$$$:::: @@@@____ aaaatttt """",,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee,,,, """"\\\\nnnn"""" }}}}
  619.  
  620.            mmmmyyyy $$$$ppppoooorrrrtttt ==== sssshhhhiiiifffftttt |||||||| 2222333344445555;;;;
  621.            mmmmyyyy $$$$pppprrrroooottttoooo ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''ttttccccpppp''''))));;;;
  622.            ssssoooocccckkkkeeeetttt((((SSSSeeeerrrrvvvveeeerrrr,,,, PPPPFFFF____IIIINNNNEEEETTTT,,,, SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,, $$$$pppprrrroooottttoooo))))        |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  623.            sssseeeettttssssoooocccckkkkoooopppptttt((((SSSSeeeerrrrvvvveeeerrrr,,,, SSSSOOOOLLLL____SSSSOOOOCCCCKKKKEEEETTTT,,,, SSSSOOOO____RRRREEEEUUUUSSSSEEEEAAAADDDDDDDDRRRR,,,,
  624.                                                ppppaaaacccckkkk((((""""llll"""",,,, 1111))))))))   |||||||| ddddiiiieeee """"sssseeeettttssssoooocccckkkkoooopppptttt:::: $$$$!!!!"""";;;;
  625.            bbbbiiiinnnndddd((((SSSSeeeerrrrvvvveeeerrrr,,,, ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppoooorrrrtttt,,,, IIIINNNNAAAADDDDDDDDRRRR____AAAANNNNYYYY))))))))        |||||||| ddddiiiieeee """"bbbbiiiinnnndddd:::: $$$$!!!!"""";;;;
  626.            lllliiiisssstttteeeennnn((((SSSSeeeerrrrvvvveeeerrrr,,,,SSSSOOOOMMMMAAAAXXXXCCCCOOOONNNNNNNN))))                            |||||||| ddddiiiieeee """"lllliiiisssstttteeeennnn:::: $$$$!!!!"""";;;;
  627.  
  628.            llllooooggggmmmmssssgggg """"sssseeeerrrrvvvveeeerrrr ssssttttaaaarrrrtttteeeedddd oooonnnn ppppoooorrrrtttt $$$$ppppoooorrrrtttt"""";;;;
  629.  
  630.            mmmmyyyy $$$$ppppaaaaddddddddrrrr;;;;
  631.  
  632.            $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;
  633.  
  634.            ffffoooorrrr (((( ;;;; $$$$ppppaaaaddddddddrrrr ==== aaaacccccccceeeepppptttt((((CCCClllliiiieeeennnntttt,,,,SSSSeeeerrrrvvvveeeerrrr))));;;; cccclllloooosssseeee CCCClllliiiieeeennnntttt)))) {{{{
  635.                mmmmyyyy(((($$$$ppppoooorrrrtttt,,,,$$$$iiiiaaaaddddddddrrrr)))) ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppaaaaddddddddrrrr))));;;;
  636.                mmmmyyyy $$$$nnnnaaaammmmeeee ==== ggggeeeetttthhhhoooossssttttbbbbyyyyaaaaddddddddrrrr(((($$$$iiiiaaaaddddddddrrrr,,,,AAAAFFFF____IIIINNNNEEEETTTT))));;;;
  637.  
  638.                llllooooggggmmmmssssgggg """"ccccoooonnnnnnnneeeeccccttttiiiioooonnnn ffffrrrroooommmm $$$$nnnnaaaammmmeeee [[[["""",,,,
  639.                        iiiinnnneeeetttt____nnnnttttooooaaaa(((($$$$iiiiaaaaddddddddrrrr)))),,,, """"]]]]
  640.                        aaaatttt ppppoooorrrrtttt $$$$ppppoooorrrrtttt"""";;;;
  641.  
  642.                pppprrrriiiinnnntttt CCCCLLLLIIIIEEEENNNNTTTT """"HHHHeeeelllllllloooo tttthhhheeeerrrreeee,,,, $$$$nnnnaaaammmmeeee,,,, iiiitttt''''ssss nnnnoooowwww """",,,,
  643.                                ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee,,,, """"\\\\nnnn"""";;;;
  644.            }}}}
  645.  
  646.        And here's a multithreaded version.  It's multithreaded in
  647.        that like most typical servers, it spawns (forks) a slave
  648.        server to handle the client request so that the master
  649.        server can quickly go back to service a new client.
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658. 30/Jan/96                perl 5.002 with                       10
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  665.  
  666.  
  667.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----TTTTwwww
  668.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  669.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  670.            BBBBEEEEGGGGIIIINNNN {{{{ $$$$EEEENNNNVVVV{{{{PPPPAAAATTTTHHHH}}}} ==== ''''////uuuussssrrrr////uuuuccccbbbb::::////bbbbiiiinnnn'''' }}}}
  671.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  672.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  673.  
  674.            ssssuuuubbbb ssssppppaaaawwwwnnnn;;;;  #### ffffoooorrrrwwwwaaaarrrrdddd ddddeeeeccccllllaaaarrrraaaattttiiiioooonnnn
  675.            ssssuuuubbbb llllooooggggmmmmssssgggg {{{{ pppprrrriiiinnnntttt """"$$$$0000 $$$$$$$$:::: @@@@____ aaaatttt """",,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee,,,, """"\\\\nnnn"""" }}}}
  676.  
  677.            mmmmyyyy $$$$ppppoooorrrrtttt ==== sssshhhhiiiifffftttt |||||||| 2222333344445555;;;;
  678.            mmmmyyyy $$$$pppprrrroooottttoooo ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''ttttccccpppp''''))));;;;
  679.            ssssoooocccckkkkeeeetttt((((SSSSeeeerrrrvvvveeeerrrr,,,, PPPPFFFF____IIIINNNNEEEETTTT,,,, SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,, $$$$pppprrrroooottttoooo))))        |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  680.            sssseeeettttssssoooocccckkkkoooopppptttt((((SSSSeeeerrrrvvvveeeerrrr,,,, SSSSOOOOLLLL____SSSSOOOOCCCCKKKKEEEETTTT,,,, SSSSOOOO____RRRREEEEUUUUSSSSEEEEAAAADDDDDDDDRRRR,,,,
  681.                                                ppppaaaacccckkkk((((""""llll"""",,,, 1111))))))))   |||||||| ddddiiiieeee """"sssseeeettttssssoooocccckkkkoooopppptttt:::: $$$$!!!!"""";;;;
  682.            bbbbiiiinnnndddd((((SSSSeeeerrrrvvvveeeerrrr,,,, ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppoooorrrrtttt,,,, IIIINNNNAAAADDDDDDDDRRRR____AAAANNNNYYYY))))))))        |||||||| ddddiiiieeee """"bbbbiiiinnnndddd:::: $$$$!!!!"""";;;;
  683.            lllliiiisssstttteeeennnn((((SSSSeeeerrrrvvvveeeerrrr,,,,SSSSOOOOMMMMAAAAXXXXCCCCOOOONNNNNNNN))))                            |||||||| ddddiiiieeee """"lllliiiisssstttteeeennnn:::: $$$$!!!!"""";;;;
  684.  
  685.            llllooooggggmmmmssssgggg """"sssseeeerrrrvvvveeeerrrr ssssttttaaaarrrrtttteeeedddd oooonnnn ppppoooorrrrtttt $$$$ppppoooorrrrtttt"""";;;;
  686.  
  687.            mmmmyyyy $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== 0000;;;;
  688.            mmmmyyyy $$$$ppppaaaaddddddddrrrr;;;;
  689.  
  690.            ssssuuuubbbb RRRREEEEAAAAPPPPEEEERRRR {{{{
  691.                $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;  #### llllooooaaaatttthhhheeee ssssyyyyssssVVVV
  692.                $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== wwwwaaaaiiiitttt;;;;
  693.                llllooooggggmmmmssssgggg """"rrrreeeeaaaappppeeeedddd $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd"""" .... (((($$$$???? ???? """" wwwwiiiitttthhhh eeeexxxxiiiitttt $$$$????"""" :::: ''''''''))));;;;
  694.            }}}}
  695.  
  696.            $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;
  697.  
  698.            ffffoooorrrr (((( $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== 0000;;;;
  699.                  (((($$$$ppppaaaaddddddddrrrr ==== aaaacccccccceeeepppptttt((((CCCClllliiiieeeennnntttt,,,,SSSSeeeerrrrvvvveeeerrrr)))))))) |||||||| $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd;;;;
  700.                  $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== 0000,,,, cccclllloooosssseeee CCCClllliiiieeeennnntttt))))
  701.            {{{{
  702.                nnnneeeexxxxtttt iiiiffff $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd;;;;
  703.                mmmmyyyy(((($$$$ppppoooorrrrtttt,,,,$$$$iiiiaaaaddddddddrrrr)))) ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppaaaaddddddddrrrr))));;;;
  704.                mmmmyyyy $$$$nnnnaaaammmmeeee ==== ggggeeeetttthhhhoooossssttttbbbbyyyyaaaaddddddddrrrr(((($$$$iiiiaaaaddddddddrrrr,,,,AAAAFFFF____IIIINNNNEEEETTTT))));;;;
  705.  
  706.                llllooooggggmmmmssssgggg """"ccccoooonnnnnnnneeeeccccttttiiiioooonnnn ffffrrrroooommmm $$$$nnnnaaaammmmeeee [[[["""",,,,
  707.                        iiiinnnneeeetttt____nnnnttttooooaaaa(((($$$$iiiiaaaaddddddddrrrr)))),,,, """"]]]]
  708.                        aaaatttt ppppoooorrrrtttt $$$$ppppoooorrrrtttt"""";;;;
  709.  
  710.                ssssppppaaaawwwwnnnn ssssuuuubbbb {{{{
  711.                    pppprrrriiiinnnntttt """"HHHHeeeelllllllloooo tttthhhheeeerrrreeee,,,, $$$$nnnnaaaammmmeeee,,,, iiiitttt''''ssss nnnnoooowwww """",,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee,,,, """"\\\\nnnn"""";;;;
  712.                    eeeexxxxeeeecccc ''''////uuuussssrrrr////ggggaaaammmmeeeessss////ffffoooorrrrttttuuuunnnneeee''''
  713.                        oooorrrr ccccoooonnnnffffeeeessssssss """"ccccaaaannnn''''tttt eeeexxxxeeeecccc ffffoooorrrrttttuuuunnnneeee:::: $$$$!!!!"""";;;;
  714.                }}}};;;;
  715.  
  716.            }}}}
  717.  
  718.            ssssuuuubbbb ssssppppaaaawwwwnnnn {{{{
  719.                mmmmyyyy $$$$ccccooooddddeeeerrrreeeeffff ==== sssshhhhiiiifffftttt;;;;
  720.  
  721.  
  722.  
  723.  
  724. 30/Jan/96                perl 5.002 with                       11
  725.  
  726.  
  727.  
  728.  
  729.  
  730. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  731.  
  732.  
  733.                uuuunnnnlllleeeessssssss ((((@@@@____ ======== 0000 &&&&&&&& $$$$ccccooooddddeeeerrrreeeeffff &&&&&&&& rrrreeeeffff(((($$$$ccccooooddddeeeerrrreeeeffff)))) eeeeqqqq ''''CCCCOOOODDDDEEEE'''')))) {{{{
  734.                    ccccoooonnnnffffeeeessssssss """"uuuussssaaaaggggeeee:::: ssssppppaaaawwwwnnnn CCCCOOOODDDDEEEERRRREEEEFFFF"""";;;;
  735.                }}}}
  736.  
  737.                mmmmyyyy $$$$ppppiiiidddd;;;;
  738.                iiiiffff ((((!!!!ddddeeeeffffiiiinnnneeeedddd(((($$$$ppppiiiidddd ==== ffffoooorrrrkkkk)))))))) {{{{
  739.                    llllooooggggmmmmssssgggg """"ccccaaaannnnnnnnooootttt ffffoooorrrrkkkk:::: $$$$!!!!"""";;;;
  740.                    rrrreeeettttuuuurrrrnnnn;;;;
  741.                }}}} eeeellllssssiiiiffff (((($$$$ppppiiiidddd)))) {{{{
  742.                    llllooooggggmmmmssssgggg """"bbbbeeeeggggaaaatttt $$$$ppppiiiidddd"""";;;;
  743.                    rrrreeeettttuuuurrrrnnnn;;;; #### iiii''''mmmm tttthhhheeee ppppaaaarrrreeeennnntttt
  744.                }}}}
  745.                #### eeeellllsssseeee iiii''''mmmm tttthhhheeee cccchhhhiiiilllldddd -------- ggggoooo ssssppppaaaawwwwnnnn
  746.  
  747.                ooooppppeeeennnn((((SSSSTTTTDDDDIIIINNNN,,,,  """"<<<<&&&&CCCClllliiiieeeennnntttt""""))))   |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt dddduuuupppp cccclllliiiieeeennnntttt ttttoooo ssssttttddddiiiinnnn"""";;;;
  748.                ooooppppeeeennnn((((SSSSTTTTDDDDOOOOUUUUTTTT,,,, """">>>>&&&&CCCClllliiiieeeennnntttt""""))))   |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt dddduuuupppp cccclllliiiieeeennnntttt ttttoooo ssssttttddddoooouuuutttt"""";;;;
  749.                ######## ooooppppeeeennnn((((SSSSTTTTDDDDEEEERRRRRRRR,,,, """">>>>&&&&SSSSTTTTDDDDOOOOUUUUTTTT"""")))) |||||||| ddddiiiieeee """"ccccaaaannnn''''tttt dddduuuupppp ssssttttddddoooouuuutttt ttttoooo ssssttttddddeeeerrrrrrrr"""";;;;
  750.                eeeexxxxiiiitttt &&&&$$$$ccccooooddddeeeerrrreeeeffff(((())));;;;
  751.            }}}}
  752.  
  753.        This server takes the trouble to clone off a child version
  754.        via _f_o_r_k_(_) for each incoming request.  That way it can
  755.        handle many requests at once, which you might not always
  756.        want.  Even if you don't _f_o_r_k_(_), the _l_i_s_t_e_n_(_) will allow
  757.        that many pending connections.  Forking servers have to be
  758.        particularly careful about cleaning up their dead children
  759.        (called "zombies" in Unix parlance), because otherwise
  760.        you'll quickly fill up your process table.
  761.  
  762.        We suggest that you use the ----TTTT flag to use taint checking
  763.        (see the _p_e_r_l_s_e_c manpage) even if we aren't running setuid
  764.        or setgid.  This is always a good idea for servers and
  765.        other programs run on behalf of someone else (like CGI
  766.        scripts), because it lessens the chances that people from
  767.        the outside will be able to compromise your system.
  768.  
  769.        Let's look at another TCP client.  This one connects to
  770.        the TCP "time" service on a number of different machines
  771.        and shows how far their clocks differ from the system on
  772.        which it's being run:
  773.  
  774.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll  ----wwww
  775.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  776.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  777.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  778.  
  779.            mmmmyyyy $$$$SSSSEEEECCCCSSSS____ooooffff____77770000____YYYYEEEEAAAARRRRSSSS ==== 2222222200008888999988888888888800000000;;;;
  780.            ssssuuuubbbb ccccttttiiiimmmmeeee {{{{ ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee((((sssshhhhiiiifffftttt)))) }}}}
  781.  
  782.            mmmmyyyy $$$$iiiiaaaaddddddddrrrr ==== ggggeeeetttthhhhoooossssttttbbbbyyyynnnnaaaammmmeeee((((''''llllooooccccaaaallllhhhhoooosssstttt''''))));;;;
  783.            mmmmyyyy $$$$pppprrrroooottttoooo ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''ttttccccpppp''''))));;;;
  784.            mmmmyyyy $$$$ppppoooorrrrtttt ==== ggggeeeettttsssseeeerrrrvvvvbbbbyyyynnnnaaaammmmeeee((((''''ttttiiiimmmmeeee'''',,,, ''''ttttccccpppp''''))));;;;
  785.            mmmmyyyy $$$$ppppaaaaddddddddrrrr ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn((((0000,,,, $$$$iiiiaaaaddddddddrrrr))));;;;
  786.            mmmmyyyy(((($$$$hhhhoooosssstttt))));;;;
  787.  
  788.  
  789.  
  790. 30/Jan/96                perl 5.002 with                       12
  791.  
  792.  
  793.  
  794.  
  795.  
  796. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  797.  
  798.  
  799.            $$$$|||| ==== 1111;;;;
  800.            pppprrrriiiinnnnttttffff """"%%%%----22224444ssss %%%%8888ssss %%%%ssss\\\\nnnn"""",,,,  """"llllooooccccaaaallllhhhhoooosssstttt"""",,,, 0000,,,, ccccttttiiiimmmmeeee((((ttttiiiimmmmeeee(((())))))));;;;
  801.  
  802.            ffffoooorrrreeeeaaaacccchhhh $$$$hhhhoooosssstttt ((((@@@@AAAARRRRGGGGVVVV)))) {{{{
  803.                pppprrrriiiinnnnttttffff """"%%%%----22224444ssss """",,,, $$$$hhhhoooosssstttt;;;;
  804.                mmmmyyyy $$$$hhhhiiiissssiiiiaaaaddddddddrrrr ==== iiiinnnneeeetttt____aaaattttoooonnnn(((($$$$hhhhoooosssstttt))))     |||||||| ddddiiiieeee """"uuuunnnnkkkknnnnoooowwwwnnnn hhhhoooosssstttt"""";;;;
  805.                mmmmyyyy $$$$hhhhiiiissssppppaaaaddddddddrrrr ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppoooorrrrtttt,,,, $$$$hhhhiiiissssiiiiaaaaddddddddrrrr))));;;;
  806.                ssssoooocccckkkkeeeetttt((((SSSSOOOOCCCCKKKKEEEETTTT,,,, PPPPFFFF____IIIINNNNEEEETTTT,,,, SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,, $$$$pppprrrroooottttoooo))))   |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  807.                ccccoooonnnnnnnneeeecccctttt((((SSSSOOOOCCCCKKKKEEEETTTT,,,, $$$$hhhhiiiissssppppaaaaddddddddrrrr))))          |||||||| ddddiiiieeee """"bbbbiiiinnnndddd:::: $$$$!!!!"""";;;;
  808.                mmmmyyyy $$$$rrrrttttiiiimmmmeeee ==== ''''    '''';;;;
  809.                rrrreeeeaaaadddd((((SSSSOOOOCCCCKKKKEEEETTTT,,,, $$$$rrrrttttiiiimmmmeeee,,,, 4444))));;;;
  810.                cccclllloooosssseeee((((SSSSOOOOCCCCKKKKEEEETTTT))));;;;
  811.                mmmmyyyy $$$$hhhhiiiissssttttiiiimmmmeeee ==== uuuunnnnppppaaaacccckkkk((((""""NNNN"""",,,, $$$$rrrrttttiiiimmmmeeee)))) ---- $$$$SSSSEEEECCCCSSSS____ooooffff____77770000____YYYYEEEEAAAARRRRSSSS ;;;;
  812.                pppprrrriiiinnnnttttffff """"%%%%8888dddd %%%%ssss\\\\nnnn"""",,,, $$$$hhhhiiiissssttttiiiimmmmeeee ---- ttttiiiimmmmeeee,,,, ccccttttiiiimmmmeeee(((($$$$hhhhiiiissssttttiiiimmmmeeee))));;;;
  813.            }}}}
  814.  
  815.  
  816.        UUUUnnnniiiixxxx----DDDDoooommmmaaaaiiiinnnn TTTTCCCCPPPP CCCClllliiiieeeennnnttttssss aaaannnndddd SSSSeeeerrrrvvvveeeerrrrssss
  817.  
  818.        That's fine for Internet-domain clients and servers, but
  819.        what local communications?  While you can use the same
  820.        setup, sometimes you don't want to.  Unix-domain sockets
  821.        are local to the current host, and are often used
  822.        internally to implement pipes.  Unlike Internet domain
  823.        sockets, UNIX domain sockets can show up in the file
  824.        system with an _l_s(1) listing.
  825.  
  826.            $$$$ llllssss ----llll ////ddddeeeevvvv////lllloooogggg
  827.            ssssrrrrwwww----rrrrwwww----rrrrwwww----  1111 rrrrooooooootttt            0000 OOOOcccctttt 33331111 00007777::::22223333 ////ddddeeeevvvv////lllloooogggg
  828.  
  829.        You can test for these with Perl's ----SSSS file test:
  830.  
  831.            uuuunnnnlllleeeessssssss (((( ----SSSS ''''////ddddeeeevvvv////lllloooogggg'''' )))) {{{{
  832.                ddddiiiieeee """"ssssoooommmmeeeetttthhhhiiiinnnngggg''''ssss wwwwiiiicccckkkkeeeedddd wwwwiiiitttthhhh tttthhhheeee pppprrrriiiinnnntttt ssssyyyysssstttteeeemmmm"""";;;;
  833.            }}}}
  834.  
  835.        Here's a sample Unix-domain client:
  836.  
  837.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----wwww
  838.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  839.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  840.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  841.            mmmmyyyy (((($$$$rrrreeeennnnddddeeeezzzzvvvvoooouuuussss,,,, $$$$lllliiiinnnneeee))));;;;
  842.  
  843.            $$$$rrrreeeennnnddddeeeezzzzvvvvoooouuuussss ==== sssshhhhiiiifffftttt |||||||| ''''////ttttmmmmpppp////ccccaaaattttssssoooocccckkkk'''';;;;
  844.            ssssoooocccckkkkeeeetttt((((SSSSOOOOCCCCKKKK,,,, PPPPFFFF____UUUUNNNNIIIIXXXX,,,, SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,, 0000))))       |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  845.            ccccoooonnnnnnnneeeecccctttt((((SSSSOOOOCCCCKKKK,,,, ssssoooocccckkkkaaaaddddddddrrrr____uuuunnnn(((($$$$rrrreeeemmmmooootttteeee))))))))         |||||||| ddddiiiieeee """"ccccoooonnnnnnnneeeecccctttt:::: $$$$!!!!"""";;;;
  846.            wwwwhhhhiiiilllleeee (((($$$$lllliiiinnnneeee ==== <<<<SSSSOOOOCCCCKKKK>>>>)))) {{{{
  847.                pppprrrriiiinnnntttt $$$$lllliiiinnnneeee;;;;
  848.            }}}}
  849.            eeeexxxxiiiitttt;;;;
  850.  
  851.        And here's a corresponding server.
  852.  
  853.  
  854.  
  855.  
  856. 30/Jan/96                perl 5.002 with                       13
  857.  
  858.  
  859.  
  860.  
  861.  
  862. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  863.  
  864.  
  865.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----TTTTwwww
  866.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  867.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  868.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  869.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  870.  
  871.            BBBBEEEEGGGGIIIINNNN {{{{ $$$$EEEENNNNVVVV{{{{PPPPAAAATTTTHHHH}}}} ==== ''''////uuuussssrrrr////uuuuccccbbbb::::////bbbbiiiinnnn'''' }}}}
  872.  
  873.            mmmmyyyy $$$$NNNNAAAAMMMMEEEE ==== ''''////ttttmmmmpppp////ccccaaaattttssssoooocccckkkk'''';;;;
  874.            mmmmyyyy $$$$uuuuaaaaddddddddrrrr ==== ssssoooocccckkkkaaaaddddddddrrrr____uuuunnnn(((($$$$NNNNAAAAMMMMEEEE))));;;;
  875.            mmmmyyyy $$$$pppprrrroooottttoooo ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''ttttccccpppp''''))));;;;
  876.  
  877.            ssssoooocccckkkkeeeetttt((((SSSSeeeerrrrvvvveeeerrrr,,,,PPPPFFFF____UUUUNNNNIIIIXXXX,,,,SSSSOOOOCCCCKKKK____SSSSTTTTRRRREEEEAAAAMMMM,,,,0000))))        |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  878.            uuuunnnnlllliiiinnnnkkkk(((($$$$NNNNAAAAMMMMEEEE))));;;;
  879.            bbbbiiiinnnndddd  ((((SSSSeeeerrrrvvvveeeerrrr,,,, $$$$uuuuaaaaddddddddrrrr))))                      |||||||| ddddiiiieeee """"bbbbiiiinnnndddd:::: $$$$!!!!"""";;;;
  880.            lllliiiisssstttteeeennnn((((SSSSeeeerrrrvvvveeeerrrr,,,,SSSSOOOOMMMMAAAAXXXXCCCCOOOONNNNNNNN))))                    |||||||| ddddiiiieeee """"lllliiiisssstttteeeennnn:::: $$$$!!!!"""";;;;
  881.  
  882.            llllooooggggmmmmssssgggg """"sssseeeerrrrvvvveeeerrrr ssssttttaaaarrrrtttteeeedddd oooonnnn $$$$NNNNAAAAMMMMEEEE"""";;;;
  883.  
  884.            $$$$SSSSIIIIGGGG{{{{CCCCHHHHLLLLDDDD}}}} ==== \\\\&&&&RRRREEEEAAAAPPPPEEEERRRR;;;;
  885.  
  886.            ffffoooorrrr (((( $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== 0000;;;;
  887.                  aaaacccccccceeeepppptttt((((CCCClllliiiieeeennnntttt,,,,SSSSeeeerrrrvvvveeeerrrr)))) |||||||| $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd;;;;
  888.                  $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd ==== 0000,,,, cccclllloooosssseeee CCCClllliiiieeeennnntttt))))
  889.            {{{{
  890.                nnnneeeexxxxtttt iiiiffff $$$$wwwwaaaaiiiitttteeeeddddppppiiiidddd;;;;
  891.                llllooooggggmmmmssssgggg """"ccccoooonnnnnnnneeeeccccttttiiiioooonnnn oooonnnn $$$$NNNNAAAAMMMMEEEE"""";;;;
  892.                ssssppppaaaawwwwnnnn ssssuuuubbbb {{{{
  893.                    pppprrrriiiinnnntttt """"HHHHeeeelllllllloooo tttthhhheeeerrrreeee,,,, iiiitttt''''ssss nnnnoooowwww """",,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee,,,, """"\\\\nnnn"""";;;;
  894.                    eeeexxxxeeeecccc ''''////uuuussssrrrr////ggggaaaammmmeeeessss////ffffoooorrrrttttuuuunnnneeee'''' oooorrrr ddddiiiieeee """"ccccaaaannnn''''tttt eeeexxxxeeeecccc ffffoooorrrrttttuuuunnnneeee:::: $$$$!!!!"""";;;;
  895.                }}}};;;;
  896.            }}}}
  897.  
  898.        As you see, it's remarkably similar to the Internet domain
  899.        TCP server, so much so, in fact, that we've omitted
  900.        several duplicate functions--_s_p_a_w_n_(_), _l_o_g_m_s_g_(_), _c_t_i_m_e_(_),
  901.        and _R_E_A_P_E_R_(_)--which are exactly the same as in the other
  902.        server.
  903.  
  904.        So why would you ever want to use a Unix domain socket
  905.        instead of a simpler named pipe?  Because a named pipe
  906.        doesn't give you sessions.  You can't tell one process's
  907.        data from another's.  With socket programming, you get a
  908.        separate session for each client: that's why _a_c_c_e_p_t_(_)
  909.        takes two arguments.
  910.  
  911.        For example, let's say that you have a long running
  912.        database server daemon that you want folks from the World
  913.        Wide Web to be able to access, but only if they go through
  914.        a CGI interface.  You'd have a small, simple CGI program
  915.        that does whatever checks and logging you feel like, and
  916.        then acts as a Unix-domain client and connects to your
  917.        private server.
  918.  
  919.  
  920.  
  921.  
  922. 30/Jan/96                perl 5.002 with                       14
  923.  
  924.  
  925.  
  926.  
  927.  
  928. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  929.  
  930.  
  931.        UUUUDDDDPPPP:::: MMMMeeeessssssssaaaaggggeeee PPPPaaaassssssssiiiinnnngggg
  932.  
  933.        Another kind of client-server setup is one that uses not
  934.        connections, but messages.  UDP communications involve
  935.        much lower overhead but also provide less reliability, as
  936.        there are no promises that messages will arrive at all,
  937.        let alone in order and unmangled.  Still, UDP offers some
  938.        advantages over TCP, including being able to "broadcast"
  939.        or "multicast" to a whole bunch of destination hosts at
  940.        once (usually on your local subnet).  If you find yourself
  941.        overly concerned about reliability and start building
  942.        checks into your message system, then you probably should
  943.        just use TCP to start with.
  944.  
  945.        Here's a UDP program similar to the sample Internet TCP
  946.        client given above.  However, instead of checking one host
  947.        at a time, the UDP version will check many of them
  948.        asynchronously by simulating a multicast and then using
  949.        _s_e_l_e_c_t_(_) to do a timed-out wait for I/O.  To do something
  950.        similar with TCP, you'd have to use a different socket
  951.        handle for each host.
  952.  
  953.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----wwww
  954.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  955.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  956.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  957.            uuuusssseeee SSSSyyyyssss::::::::HHHHoooossssttttnnnnaaaammmmeeee;;;;
  958.  
  959.            mmmmyyyy (((( $$$$ccccoooouuuunnnntttt,,,, $$$$hhhhiiiissssiiiiaaaaddddddddrrrr,,,, $$$$hhhhiiiissssppppaaaaddddddddrrrr,,,, $$$$hhhhiiiissssttttiiiimmmmeeee,,,,
  960.                 $$$$hhhhoooosssstttt,,,, $$$$iiiiaaaaddddddddrrrr,,,, $$$$ppppaaaaddddddddrrrr,,,, $$$$ppppoooorrrrtttt,,,, $$$$pppprrrroooottttoooo,,,,
  961.                 $$$$rrrriiiinnnn,,,, $$$$rrrroooouuuutttt,,,, $$$$rrrrttttiiiimmmmeeee,,,, $$$$SSSSEEEECCCCSSSS____ooooffff____77770000____YYYYEEEEAAAARRRRSSSS))));;;;
  962.  
  963.            $$$$SSSSEEEECCCCSSSS____ooooffff____77770000____YYYYEEEEAAAARRRRSSSS      ==== 2222222200008888999988888888888800000000;;;;
  964.  
  965.            $$$$iiiiaaaaddddddddrrrr ==== ggggeeeetttthhhhoooossssttttbbbbyyyynnnnaaaammmmeeee((((hhhhoooossssttttnnnnaaaammmmeeee(((())))))));;;;
  966.            $$$$pppprrrroooottttoooo ==== ggggeeeettttpppprrrroooottttoooobbbbyyyynnnnaaaammmmeeee((((''''uuuuddddpppp''''))));;;;
  967.            $$$$ppppoooorrrrtttt ==== ggggeeeettttsssseeeerrrrvvvvbbbbyyyynnnnaaaammmmeeee((((''''ttttiiiimmmmeeee'''',,,, ''''uuuuddddpppp''''))));;;;
  968.            $$$$ppppaaaaddddddddrrrr ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn((((0000,,,, $$$$iiiiaaaaddddddddrrrr))));;;; #### 0000 mmmmeeeeaaaannnnssss lllleeeetttt kkkkeeeerrrrnnnneeeellll ppppiiiicccckkkk
  969.  
  970.            ssssoooocccckkkkeeeetttt((((SSSSOOOOCCCCKKKKEEEETTTT,,,, PPPPFFFF____IIIINNNNEEEETTTT,,,, SSSSOOOOCCCCKKKK____DDDDGGGGRRRRAAAAMMMM,,,, $$$$pppprrrroooottttoooo))))   |||||||| ddddiiiieeee """"ssssoooocccckkkkeeeetttt:::: $$$$!!!!"""";;;;
  971.            bbbbiiiinnnndddd((((SSSSOOOOCCCCKKKKEEEETTTT,,,, $$$$ppppaaaaddddddddrrrr))))                          |||||||| ddddiiiieeee """"bbbbiiiinnnndddd:::: $$$$!!!!"""";;;;
  972.  
  973.            $$$$|||| ==== 1111;;;;
  974.            pppprrrriiiinnnnttttffff """"%%%%----11112222ssss %%%%8888ssss %%%%ssss\\\\nnnn"""",,,,  """"llllooooccccaaaallllhhhhoooosssstttt"""",,,, 0000,,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee ttttiiiimmmmeeee;;;;
  975.            $$$$ccccoooouuuunnnntttt ==== 0000;;;;
  976.            ffffoooorrrr $$$$hhhhoooosssstttt ((((@@@@AAAARRRRGGGGVVVV)))) {{{{
  977.                $$$$ccccoooouuuunnnntttt++++++++;;;;
  978.                $$$$hhhhiiiissssiiiiaaaaddddddddrrrr ==== iiiinnnneeeetttt____aaaattttoooonnnn(((($$$$hhhhoooosssstttt))))    |||||||| ddddiiiieeee """"uuuunnnnkkkknnnnoooowwwwnnnn hhhhoooosssstttt"""";;;;
  979.                $$$$hhhhiiiissssppppaaaaddddddddrrrr ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$ppppoooorrrrtttt,,,, $$$$hhhhiiiissssiiiiaaaaddddddddrrrr))));;;;
  980.                ddddeeeeffffiiiinnnneeeedddd((((sssseeeennnndddd((((SSSSOOOOCCCCKKKKEEEETTTT,,,, 0000,,,, 0000,,,, $$$$hhhhiiiissssppppaaaaddddddddrrrr))))))))    |||||||| ddddiiiieeee """"sssseeeennnndddd $$$$hhhhoooosssstttt:::: $$$$!!!!"""";;;;
  981.            }}}}
  982.  
  983.            $$$$rrrriiiinnnn ==== '''''''';;;;
  984.            vvvveeeecccc(((($$$$rrrriiiinnnn,,,, ffffiiiilllleeeennnnoooo((((SSSSOOOOCCCCKKKKEEEETTTT)))),,,, 1111)))) ==== 1111;;;;
  985.  
  986.  
  987.  
  988. 30/Jan/96                perl 5.002 with                       15
  989.  
  990.  
  991.  
  992.  
  993.  
  994. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  995.  
  996.  
  997.            #### ttttiiiimmmmeeeeoooouuuutttt aaaafffftttteeeerrrr 11110000....0000 sssseeeeccccoooonnnnddddssss
  998.            wwwwhhhhiiiilllleeee (((($$$$ccccoooouuuunnnntttt &&&&&&&& sssseeeelllleeeecccctttt(((($$$$rrrroooouuuutttt ==== $$$$rrrriiiinnnn,,,, uuuunnnnddddeeeeffff,,,, uuuunnnnddddeeeeffff,,,, 11110000....0000)))))))) {{{{
  999.                $$$$rrrrttttiiiimmmmeeee ==== '''''''';;;;
  1000.                (((($$$$hhhhiiiissssppppaaaaddddddddrrrr ==== rrrreeeeccccvvvv((((SSSSOOOOCCCCKKKKEEEETTTT,,,, $$$$rrrrttttiiiimmmmeeee,,,, 4444,,,, 0000))))))))        |||||||| ddddiiiieeee """"rrrreeeeccccvvvv:::: $$$$!!!!"""";;;;
  1001.                (((($$$$ppppoooorrrrtttt,,,, $$$$hhhhiiiissssiiiiaaaaddddddddrrrr)))) ==== ssssoooocccckkkkaaaaddddddddrrrr____iiiinnnn(((($$$$hhhhiiiissssppppaaaaddddddddrrrr))));;;;
  1002.                $$$$hhhhoooosssstttt ==== ggggeeeetttthhhhoooossssttttbbbbyyyyaaaaddddddddrrrr(((($$$$hhhhiiiissssiiiiaaaaddddddddrrrr,,,, AAAAFFFF____IIIINNNNEEEETTTT))));;;;
  1003.                $$$$hhhhiiiissssttttiiiimmmmeeee ==== uuuunnnnppppaaaacccckkkk((((""""NNNN"""",,,, $$$$rrrrttttiiiimmmmeeee)))) ---- $$$$SSSSEEEECCCCSSSS____ooooffff____77770000____YYYYEEEEAAAARRRRSSSS ;;;;
  1004.                pppprrrriiiinnnnttttffff """"%%%%----11112222ssss """",,,, $$$$hhhhoooosssstttt;;;;
  1005.                pppprrrriiiinnnnttttffff """"%%%%8888dddd %%%%ssss\\\\nnnn"""",,,, $$$$hhhhiiiissssttttiiiimmmmeeee ---- ttttiiiimmmmeeee,,,, ssssccccaaaallllaaaarrrr llllooooccccaaaallllttttiiiimmmmeeee(((($$$$hhhhiiiissssttttiiiimmmmeeee))));;;;
  1006.                $$$$ccccoooouuuunnnntttt--------;;;;
  1007.            }}}}
  1008.  
  1009.  
  1010. SSSSyyyyssssVVVV IIIIPPPPCCCC
  1011.        While System V IPC isn't so widely used as sockets, it
  1012.        still has some interesting uses.  You can't, however,
  1013.        effectively use SysV IPC or Berkeley _m_m_a_p_(_) to have shared
  1014.        memory so as to share a variable amongst several
  1015.        processes.  That's because Perl would reallocate your
  1016.        string when you weren't wanting it to.
  1017.  
  1018.        Here's a small example showing shared memory usage.
  1019.  
  1020.            $$$$IIIIPPPPCCCC____PPPPRRRRIIIIVVVVAAAATTTTEEEE ==== 0000;;;;
  1021.            $$$$IIIIPPPPCCCC____RRRRMMMMIIIIDDDD ==== 0000;;;;
  1022.            $$$$ssssiiiizzzzeeee ==== 2222000000000000;;;;
  1023.            $$$$kkkkeeeeyyyy ==== sssshhhhmmmmggggeeeetttt(((($$$$IIIIPPPPCCCC____PPPPRRRRIIIIVVVVAAAATTTTEEEE,,,, $$$$ssssiiiizzzzeeee ,,,, 0000777777777777 ))));;;;
  1024.            ddddiiiieeee uuuunnnnlllleeeessssssss ddddeeeeffffiiiinnnneeeedddd $$$$kkkkeeeeyyyy;;;;
  1025.  
  1026.            $$$$mmmmeeeessssssssaaaaggggeeee ==== """"MMMMeeeessssssssaaaaggggeeee ####1111"""";;;;
  1027.            sssshhhhmmmmwwwwrrrriiiitttteeee(((($$$$kkkkeeeeyyyy,,,, $$$$mmmmeeeessssssssaaaaggggeeee,,,, 0000,,,, 66660000 )))) |||||||| ddddiiiieeee """"$$$$!!!!"""";;;;
  1028.            sssshhhhmmmmrrrreeeeaaaadddd(((($$$$kkkkeeeeyyyy,,,,$$$$bbbbuuuuffffffff,,,,0000,,,,66660000)))) |||||||| ddddiiiieeee """"$$$$!!!!"""";;;;
  1029.  
  1030.            pppprrrriiiinnnntttt $$$$bbbbuuuuffffffff,,,,""""\\\\nnnn"""";;;;
  1031.  
  1032.            pppprrrriiiinnnntttt """"ddddeeeelllleeeettttiiiinnnngggg $$$$kkkkeeeeyyyy\\\\nnnn"""";;;;
  1033.            sssshhhhmmmmccccttttllll(((($$$$kkkkeeeeyyyy ,,,,$$$$IIIIPPPPCCCC____RRRRMMMMIIIIDDDD,,,, 0000)))) |||||||| ddddiiiieeee """"$$$$!!!!"""";;;;
  1034.  
  1035.        Here's an example of a semaphore:
  1036.  
  1037.            $$$$IIIIPPPPCCCC____KKKKEEEEYYYY ==== 1111222233334444;;;;
  1038.            $$$$IIIIPPPPCCCC____RRRRMMMMIIIIDDDD ==== 0000;;;;
  1039.            $$$$IIIIPPPPCCCC____CCCCRRRREEEEAAAATTTTEEEE ==== 0000000000001111000000000000;;;;
  1040.            $$$$kkkkeeeeyyyy ==== sssseeeemmmmggggeeeetttt(((($$$$IIIIPPPPCCCC____KKKKEEEEYYYY,,,, $$$$nnnnsssseeeemmmmssss ,,,, 0000666666666666 |||| $$$$IIIIPPPPCCCC____CCCCRRRREEEEAAAATTTTEEEE ))));;;;
  1041.            ddddiiiieeee iiiiffff !!!!ddddeeeeffffiiiinnnneeeedddd(((($$$$kkkkeeeeyyyy))));;;;
  1042.            pppprrrriiiinnnntttt """"$$$$kkkkeeeeyyyy\\\\nnnn"""";;;;
  1043.  
  1044.        Put this code in a separate file to be run in more that
  1045.        one process Call the file _t_a_k_e:
  1046.  
  1047.            #### ccccrrrreeeeaaaatttteeee aaaa sssseeeemmmmaaaapppphhhhoooorrrreeee
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054. 30/Jan/96                perl 5.002 with                       16
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  1061.  
  1062.  
  1063.            $$$$IIIIPPPPCCCC____KKKKEEEEYYYY ==== 1111222233334444;;;;
  1064.            $$$$kkkkeeeeyyyy ==== sssseeeemmmmggggeeeetttt(((($$$$IIIIPPPPCCCC____KKKKEEEEYYYY,,,,  0000 ,,,, 0000 ))));;;;
  1065.            ddddiiiieeee iiiiffff !!!!ddddeeeeffffiiiinnnneeeedddd(((($$$$kkkkeeeeyyyy))));;;;
  1066.  
  1067.            $$$$sssseeeemmmmnnnnuuuummmm ==== 0000;;;;
  1068.            $$$$sssseeeemmmmffffllllaaaagggg ==== 0000;;;;
  1069.  
  1070.            #### ''''ttttaaaakkkkeeee'''' sssseeeemmmmaaaapppphhhhoooorrrreeee
  1071.            #### wwwwaaaaiiiitttt ffffoooorrrr sssseeeemmmmaaaapppphhhhoooorrrreeee ttttoooo bbbbeeee zzzzeeeerrrroooo
  1072.            $$$$sssseeeemmmmoooopppp ==== 0000;;;;
  1073.            $$$$ooooppppssssttttrrrriiiinnnngggg1111 ==== ppppaaaacccckkkk((((""""ssssssssssss"""",,,, $$$$sssseeeemmmmnnnnuuuummmm,,,, $$$$sssseeeemmmmoooopppp,,,, $$$$sssseeeemmmmffffllllaaaagggg))));;;;
  1074.  
  1075.            #### IIIInnnnccccrrrreeeemmmmeeeennnntttt tttthhhheeee sssseeeemmmmaaaapppphhhhoooorrrreeee ccccoooouuuunnnntttt
  1076.            $$$$sssseeeemmmmoooopppp ==== 1111;;;;
  1077.            $$$$ooooppppssssttttrrrriiiinnnngggg2222 ==== ppppaaaacccckkkk((((""""ssssssssssss"""",,,, $$$$sssseeeemmmmnnnnuuuummmm,,,, $$$$sssseeeemmmmoooopppp,,,,  $$$$sssseeeemmmmffffllllaaaagggg))));;;;
  1078.            $$$$ooooppppssssttttrrrriiiinnnngggg ==== $$$$ooooppppssssttttrrrriiiinnnngggg1111 .... $$$$ooooppppssssttttrrrriiiinnnngggg2222;;;;
  1079.  
  1080.            sssseeeemmmmoooopppp(((($$$$kkkkeeeeyyyy,,,,$$$$ooooppppssssttttrrrriiiinnnngggg)))) |||||||| ddddiiiieeee """"$$$$!!!!"""";;;;
  1081.  
  1082.        Put this code in a separate file to be run in more that
  1083.        one process Call this file _g_i_v_e:
  1084.  
  1085.            #### ''''ggggiiiivvvveeee'''' tttthhhheeee sssseeeemmmmaaaapppphhhhoooorrrreeee
  1086.            #### rrrruuuunnnn tttthhhhiiiissss iiiinnnn tttthhhheeee oooorrrriiiiggggiiiinnnnaaaallll pppprrrroooocccceeeessssssss aaaannnndddd yyyyoooouuuu wwwwiiiillllllll sssseeeeeeee
  1087.            #### tttthhhhaaaatttt tttthhhheeee sssseeeeccccoooonnnndddd pppprrrroooocccceeeessssssss ccccoooonnnnttttiiiinnnnuuuueeeessss
  1088.  
  1089.            $$$$IIIIPPPPCCCC____KKKKEEEEYYYY ==== 1111222233334444;;;;
  1090.            $$$$kkkkeeeeyyyy ==== sssseeeemmmmggggeeeetttt(((($$$$IIIIPPPPCCCC____KKKKEEEEYYYY,,,, 0000,,,, 0000))));;;;
  1091.            ddddiiiieeee iiiiffff !!!!ddddeeeeffffiiiinnnneeeedddd(((($$$$kkkkeeeeyyyy))));;;;
  1092.  
  1093.            $$$$sssseeeemmmmnnnnuuuummmm ==== 0000;;;;
  1094.            $$$$sssseeeemmmmffffllllaaaagggg ==== 0000;;;;
  1095.  
  1096.            #### DDDDeeeeccccrrrreeeemmmmeeeennnntttt tttthhhheeee sssseeeemmmmaaaapppphhhhoooorrrreeee ccccoooouuuunnnntttt
  1097.            $$$$sssseeeemmmmoooopppp ==== ----1111;;;;
  1098.            $$$$ooooppppssssttttrrrriiiinnnngggg ==== ppppaaaacccckkkk((((""""ssssssssssss"""",,,, $$$$sssseeeemmmmnnnnuuuummmm,,,, $$$$sssseeeemmmmoooopppp,,,, $$$$sssseeeemmmmffffllllaaaagggg))));;;;
  1099.  
  1100.            sssseeeemmmmoooopppp(((($$$$kkkkeeeeyyyy,,,,$$$$ooooppppssssttttrrrriiiinnnngggg)))) |||||||| ddddiiiieeee """"$$$$!!!!"""";;;;
  1101.  
  1102.  
  1103. WWWWAAAARRRRNNNNIIIINNNNGGGG
  1104.        The SysV IPC code above was written long ago, and it's
  1105.        definitely clunky looking.  It should at the very least be
  1106.        made to uuuusssseeee ssssttttrrrriiiicccctttt and rrrreeeeqqqquuuuiiiirrrreeee """"ssssyyyyssss////iiiippppcccc....pppphhhh"""".  Better yet,
  1107.        perhaps someone should create an IIIIPPPPCCCC::::::::SSSSyyyyssssVVVV module the way
  1108.        we have the SSSSoooocccckkkkeeeetttt module for normal client-server
  1109.        communications.
  1110.  
  1111.        (... time passes)
  1112.  
  1113.        Voila!  Check out the IPC::SysV modules written by Jack
  1114.        Shirazi.  You can find them at a CPAN store near you.
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120. 30/Jan/96                perl 5.002 with                       17
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  1127.  
  1128.  
  1129. NNNNOOOOTTTTEEEESSSS
  1130.        If you are running under version 5.000 (dubious) or 5.001,
  1131.        you can still use most of the examples in this document.
  1132.        You may have to remove the uuuusssseeee ssssttttrrrriiiicccctttt and some of the _m_y_(_)
  1133.        statements for 5.000, and for both you'll have to load in
  1134.        version 1.2 of the _S_o_c_k_e_t_._p_m module, which was/is/shall-be
  1135.        included in _p_e_r_l_5_._0_0_1_o.
  1136.  
  1137.        Most of these routines quietly but politely return uuuunnnnddddeeeeffff
  1138.        when they fail instead of causing your program to die
  1139.        right then and there due to an uncaught exception.
  1140.        (Actually, some of the new _S_o_c_k_e_t conversion functions
  1141.        _c_r_o_a_k_(_) on bad arguments.)  It is therefore essential that
  1142.        you should check the return values fo these functions.
  1143.        Always begin your socket programs this way for optimal
  1144.        success, and don't forget to add ----TTTT taint checking flag to
  1145.        the pound-bang line for servers:
  1146.  
  1147.            ####!!!!////uuuussssrrrr////bbbbiiiinnnn////ppppeeeerrrrllll ----wwww
  1148.            rrrreeeeqqqquuuuiiiirrrreeee 5555....000000002222;;;;
  1149.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  1150.            uuuusssseeee ssssiiiiggggttttrrrraaaapppp;;;;
  1151.            uuuusssseeee SSSSoooocccckkkkeeeetttt;;;;
  1152.  
  1153.  
  1154. BBBBUUUUGGGGSSSS
  1155.        All these routines create system-specific portability
  1156.        problems.  As noted elsewhere, Perl is at the mercy of
  1157.        your C libraries for much of its system behaviour.  It's
  1158.        probably safest to assume broken SysV semantics for
  1159.        signals and to stick with simple TCP and UDP socket
  1160.        operations; e.g. don't try to pass open filedescriptors
  1161.        over a local UDP datagram socket if you want your code to
  1162.        stand a chance of being portable.
  1163.  
  1164.        Because few vendors provide C libraries that are safely
  1165.        re-entrant, the prudent programmer will do little else
  1166.        within a handler beyond _d_i_e_(_) to raise an exception and
  1167.        _l_o_n_g_j_m_p(3) out.
  1168.  
  1169. AAAAUUUUTTTTHHHHOOOORRRR
  1170.        Tom Christiansen, with occasional vestiges of Larry Wall's
  1171.        original version.
  1172.  
  1173. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1174.        Besides the obvious functions in the _p_e_r_l_f_u_n_c manpage, you
  1175.        should also check out the _m_o_d_u_l_e_s file at your nearest
  1176.        CPAN site.  (See the _p_e_r_l_m_o_d manpage or best yet, the _P_e_r_l
  1177.        _F_A_Q for a description of what CPAN is and where to get
  1178.        it.)  Section 5 of the _m_o_d_u_l_e_s file is devoted to
  1179.        "Networking, Device Control (modems) and Interprocess
  1180.        Communication", and contains numerous unbundled modules
  1181.        numerous networking modules, Chat and Expect operations,
  1182.        CGI programming, DCE, FTP, IPC, NNTP, Proxy, Ptty, RPC,
  1183.  
  1184.  
  1185.  
  1186. 30/Jan/96                perl 5.002 with                       18
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. PERLIPC(1)     User Contributed Perl Documentation     PERLIPC(1)
  1193.  
  1194.  
  1195.        SNMP, SMTP, Telnet, Threads, and ToolTalk--just to name a
  1196.        few.
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252. 30/Jan/96                perl 5.002 with                       19
  1253.  
  1254.  
  1255.