hello,
You have misunderstood my meanings.
I fork the child process in socket server's parent process,and the socket 
server accept the requests from socket clients,which are distributed in about 
200 different hosts.
I don't do the IPC communication of child-to-parent socket.:-)

-----Original Message-----
>From: zentara <[EMAIL PROTECTED]>
>Sent: Feb 1, 2006 6:55 AM
>To: beginners@perl.org
>Subject: Re: how to share variable across multi-processes
>
>On Tue, 31 Jan 2006 11:13:16 -0500 (EST), [EMAIL PROTECTED] (Jeff
>Pang) wrote:
>
>>hi,Zentara,
>>I know little about perl's thread,so I am not certain to make it run 
>>successfully under thread mode.
>>In fact,my program is not complicated.It accept the following  data-line from 
>>about 200 clients:
>>
>>1_uee002##_01_100g836j:2048000:get
>>
>>and use these elements to build a hash:
>>
>>    my %records;
>>    my ($mid,$size,$type) = split(/:/,$line);
>>    my $timestamp = time();
>>    $records{$mid}->{$timestamp}+=$size;
>>
>>When a request is coming,I want to fork a child process to handle it.
>>
>>    my $child = fork();
>>    die "can't fork:$!" unless defined $child;
>>    if ($child==0)
>>    {
>>        do_something_to_hash();
>>    }
>>
>>here,I want to modify the global hash %records in each child.These 
>>modifications include insert,modify,or delete items.
>>
>>Now I just use single process to resolve the problem,since I have not get a 
>>way to get the variable be shared across multi-processes.and,I watched that 
>>when the server have run for one whole day,it used about 60M memory.
>>
>>Following Zentara and Chas's advices,I know there are at least three ways to 
>>do that:
>>
>>1)Threads;
>>2)IPC::Shareable;
>>3)tie the hash to DBM,and write to local filesystem.
>>
>>I'll try those ways apartly.Thanks for all.
>
>There is another "tried-tested-and-true" method for handling your IPC,
>....sockets.  To me, if you are forking from a parent, that would be the
>most solid way to do it.
>
>Set up a server in your parent to receive input on a certain socket, say
>13333(choose any unused socket).
>
>Then when you fork your clients, include socket code in them, to connect
>to 13333, and write their data to it. When the parent receives the data,
>process it somehow according to your needs.
>
>Socket code is the conventional way of doing IPC.
>
>The hardest part would be setting up a loop that both waits for
>incoming new connections, and receives data from existing
>child processes. But there are many examples out there.
>
>
>
>
>
>
>
>
>
>
>
>
>-- 
>I'm not really a human, but I play one on earth.
>http://zentara.net/japh.html
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to