From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Arijit
Das
        Sent: 24 August 2005 16:42
        To: [email protected];
[email protected]
        Subject: Sharing Variables among Processes...
        
        
        Its about sharing a Perl Variable among parent and child
processes.
         
        Do you know of any design pattern or technique by which this can
be achieved?
         
        What I want is this...
         
        $shared_var = 10;
         
        if ($pid = fork) {
            sleep 10;
            print "$shared_var\n"; # Should show the child's changes...
        } elsif (defined $pid) {
            $shared_var = 12;
            exit 0;
        }
         
        I want the change in the shared variable to be reflected to the
parent process immediately...basically, same variable in memory should
be changed. 
         
In general, you can't share Perl variables between multiple processes.
There are mechanisms for sharing data between process using IPC (inter
process communication) which include platform dependent features like
shared memory or memory mapped files (you don't say which platform you
are using), or more general techniques like sockets.

You can share Perl variables between threads, however, if your Perl is
built with thread support.

You don't say what you are trying to accomplish. Why do you think that
you need to share a Perl variable between 2 processes?

HTH

-- 
Brian Raven
 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
-----------------------------------------------------------------------


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to