1

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

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Matt
  • 295
  • 3
  • 6
  • 17

2 Answers2

2

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.)

Ether
  • 53,118
  • 13
  • 86
  • 159
  • Probably better in the long term to link to http://stackoverflow.com/questions/251705/how-can-i-use-a-new-perl-module-without-install-permissions instead because it can be more easily improved by the community than mst's article. – daxim Feb 03 '11 at 12:45
-1

Have you tried threads::shared?

  • I was seeing some weird behavior with Perl threading, so I switched to using forks instead. I'm wondering if there is a way I can accomplish this without threads and I unfortunately don't have access to IPC::Shareable =/ – Matt Feb 02 '11 at 21:06
  • Why don't you have access to IPC::Shareable? It's all right [here](http://cpansearch.perl.org/src/BSUGARS/IPC-Shareable-0.60/lib/IPC/Shareable.pm) and [here](http://cpansearch.perl.org/src/BSUGARS/IPC-Shareable-0.60/lib/IPC/Shareable/SharedMem.pm). – mob Feb 02 '11 at 21:13
  • The computers I'm working with are on a closed network and don't come with that package by default. I could probably get it installed on all my machines if I pushed hard enough, but I was hoping there was another way I could do this. – Matt Feb 02 '11 at 21:17
  • 2
    My point is you don't need to install it. You can just copy and paste it into your script. – mob Feb 02 '11 at 21:43