问题
I need to share variables between different Children processes and my Parent process in Perl without the use of IPC::Shareable.
I basically just need to have a global variable that all processes would be able to read/write to. Also, the variable only needs write access from the parent if that would make my answer simpler. The Children only need to read it.
Edit: My problem could also be solved if there is a way for me to pass a message from one child process to another
回答1:
From the information you have provided it's difficult to tell which is the best solution, but there are a few options available to you:
- pass a message between your processes using sockets, or pipes
- use a database that both processes read and write to
- use a file(s) that both processes read and write to (you could use signals to tell a process when it is time to read from a file)
- set up a memcache server to share information
...However, since your real problem might actually be "how can I do something in Perl that requires a module that isn't installed on my system, and I don't have root control over this box and sysadmins can't or won't cooperate?". the best answer is "use local::lib", but you can read more options in Matt Trout's blog post "But I can't use CPAN!". (I swear I post this link every single week.)
回答2:
Have you tried threads::shared?
来源:https://stackoverflow.com/questions/4879797/share-variables-between-child-processes-in-perl-without-ipcshareable