arkturuz has asked for the wisdom of the Perl Monks concerning the following question:

Hello great monkz!

When I run my perl application (e.g. a custom web server) I would like to write various information somewhere in memory (in /proc perhaps??) so that I can with some other program read that information and know what my app does at that time.

The reason I want this feature to write to memory instead to disk is because I want it constantly updated (I would not like to write x bytes of data to disk, constantly overwriting old information).

How can I acomplish this?

  • Comment on Registering various app states at run-time

Replies are listed 'Best First'.
Re: Registering various app states at run-time
by davorg (Chancellor) on Feb 13, 2006 at 11:57 UTC

    Sounds like you're looking for shared memory. A CPAN search for "shared" gives some potential starting points.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Thanks for hint!

      I dowloaded Net::Shared and it seems it's the thing I need.

Re: Registering various app states at run-time
by salva (Canon) on Feb 13, 2006 at 12:41 UTC
    /proc is highly OS dependant and on most systems, AFAIK, only for communication with the kernel.

    If you are writting some network server in a non blocking fashion (so, using select), you can use another TCP port or a Unix socket to serve the status (or if it is a web server, mapping it to a specific url).

    If performance is what bothers you, you can use some shared memory module or use a ram file system (for instance, /tmp on Solaris).

    You can also write status to disk only when a signal is sent to the process, but be carefull on how you handle signals from perl because it is easy to crash the app if you try to do something complex there that allocates memory.

      Well, it is a network server and already finished. I want to add this feature so that I can monitor it all the time with some second app. (Currently, server is writing errors and warnings to a log file.) I am considering using a Net::Shared module.
        Net::Shared doesn't look like a good option to me. Looking at its source code I have found that it forks a new process that acts as a TCP server that is where state is maintained. The problem is that it is a blocking server an so, any stalled connection will cause your full server to stall.

        Besides that, the overhead could be actually higher than that of just writting the state to disk.

        Other modules like IPC::Shareable using shared memory should be a better option.

Re: Registering various app states at run-time
by Ultra (Hermit) on Feb 13, 2006 at 12:13 UTC

    Be aware that /proc is 100% mounted on GNU/Linux. Other Unices don't have it mounted by default, and some of them don't implement /proc at all ...

    Dodge This!