I need to access a pubblic shared memory , given it's pathname as using ftok C function.

key_t ftok(const char *pathname, int proj_id);

It seems that in perl ftok is non available so for now I build my own implementation of ftok which I call from perl as show here:

$file_shmem = "/tmp/IPC/shared_memory1"; $size_shmem = 18640; open( F, "./ftok $file_shmem 1 |" ); $s1 = <F>; close F; chomp $s1; $ipckey = "0x$s1"; print "IPC-KEY of ($file_shmem) is $ipckey \n"; $idshm = shmget( $ipckey, $size_shmem, 0666 ) || die "\n Creation o +f shared memory failed $! \n"; print "IPC-SHMEM: id $idshm \n"; shmread( $idshm, $data_shmem, 0, $size_shmem ) || warn "\n\n Error +reading shared-memory: $! \n";

All this will work, but is not polite and it seems strange to me that perl have not an implementatio for ftok.

Can you provide me some suggestion on that topic ?

regards, Enzo

Code tags added by GrandFather


In reply to use ftok to access shared memory by earlati2

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.