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

I'm having a spot of bother with shared memory. When executing the line
tie %SPAM, 'IPC::Shareable', 'SPLM', {create => 1, mode => 0644} unless defined %SPAM;
I get the error Munged shared memory segment (size exceeded?) Is there any way (short of rebooting) to rectify this problem?

Replies are listed 'Best First'.
Re: shared memory problems
by Anonymous Monk on Nov 06, 2000 at 18:52 UTC
    OK, all sorted. To answer my own question:
    use ipcs to identify the shared memory segment/semaphore
    use ipcrm -m shmid -s semkey to clear memory/semaphores
    Thank you o'Reilly!
RE: shared memory problems
by AgentM (Curate) on Nov 07, 2000 at 03:49 UTC
    Note that this is Sys V-specific code. BSD-based and other kernels have no such support for this type of shared memory. The most portable way to create shared memory (UN*X, that is) is to create memory using mmap() and mmap() again (with MAP_SHARED) in the other process which is obviously very different from your Sys V shmget() which is implicitly called in your tie() line (you'll also want to look into memory mutexing). Unfortunately, the IPC modules on CPAN tend to tilt more towards the Sys V side (which is not always the best thing). Of course, you can disregard my commentary if you're not planning on throwing your code from computer to computer, but, in your shoes, I might consider POSIX IPC which is partially supported in the IPC modules, partially in POSIX, and partially not at all. It's still worth looking into, though. Hopefully, Perl6 will include more POSIX stuff. The shm_open() POSIX function is simple enough, though, to punch through yourself in perl. Have fun!
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.