in reply to Use of shared memory to persist data between child processes

My approach to shared memory is to avoid it as long as possible, as the locking issues and resource issues are a nightmare to me.

I would either go via a database to which all slaves write and from which the master reads (if at all necessary), several, differently named files, one per slave, which the master collects as soon as they are completely written, renames and then reads, or via TCP connections that the slaves open to the master and transfer the data through.

These mechanisms are most likely slower than shared memory, but once you've killed both the master process and the slaves, you can inspect the files or the database to see what went wrong, and you know that if you erase the files respectively the database table, your system is in a fresh state.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Use of shared memory to persist data between child processes
by skx (Parson) on Oct 09, 2003 at 10:34 UTC

     I'm afraid that I cannot rely upon a database being present as this is some very simple standalone code. (Which also runs under Windows).

     The basic code is something that forks to serve HTTP like requests and I wish to have a means of determining which requests are "active". As the files served are very large it's very likely that requests take a significant amount of time to process.

     I think that I could use a seperate file for each slave - so that when the child forms it will write to a file "/var/server/child-ip.$$" and the master parent can read these .

     That's a more basic idea than I'd considered but I see nothing wrong with it, and there's no synchronisation issues to deal with at all.

    Steve
    ---
    steve.org.uk

      I'm afraid that I cannot rely upon a database being present as this is some very simple standalone code.

      DBD::SQLite

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated