I'm trying to attach to a specific memory address with IPC::SharedMem, but keep getting in at 0x00000000 instead. Here's the ipcs output indicating what I specifically want to monitor:

------ Shared Memory Segments -------- key shmid owner perms bytes nattch stat +us 0x00000000 98304 root 600 67108864 20 dest 0x0052e2c1 65537 postgres 600 56 5 0xf102ee77 131074 XXXXXXX 700 65535 0
I'm trying to monitor the one whose username I have redacted, at 0xf102ee77. Here's my code for trying to do so:
use strict; use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR SHM_RDONLY); use IPC::SharedMem; use Class::Struct; my $key = '0xf102ee77'; my $shm = IPC::SharedMem->new(${key},65535,SHM_RDONLY); &fl_die("Could not open shared memory segment.") unless defined(${shm} +); my $stat = ${shm}->stat; &fl_die("Could not stat shared memory segment.") unless defined(${stat +}); my $concount = ${stat}->nattch;
Here's what my actual shared memory requests are creating (even without the create flag being used):
0x00000000 393224 root 0 65535 0 0x00000000 425993 root 0 65535 0 0x00000000 458762 root 0 65535 0 0x00000000 491531 root 0 65535 0 0x00000000 524300 root 0 65535 0 0x00000000 557069 root 0 65535 0 0x00000000 589838 root 0 65535 0

While I get no errors, nattch keeps reading zero, largely because I'm getting in at 0x00000000 instead of the requested address. If I try unquoting the key value, it won't even attach to any shared memory, and comes back undefined at the constructor call.

May I please get some assistance on this? This is my first time needing to deal with shared memory. I know what I'm after (nattch), but this module is not the best documented in the world.

Thanks!


In reply to Using IPC::SharedMem to get nattch for a specific address? by fairlite

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.