Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, I'm trying to determine how mmap works with Perl and Sys::Mmap on linux. I have a c program, which when I run it, I can see it's shmid listed with "ipcs -m". That's all well and good. So I'm trying to create the simplest Perl program to do the same thing, but I can't seem to get it to show it's shmid with ipcs -m. I'm wondering if I'm thinking about this wrong, or whether I'm setting it up right, or whether there is something odd with my linux setup. I'm using kernel 2.6.10. Anyways, here is the code, if anyone can show me how to make the shmid show up in "ipcs -m" I would be grateful.

Also the shmid, shown by Perl, dosn't seem to match the format listed by ipcs...is it a decimal versus hex conversion?

Update: Corrected return value for mmap, thanks Aristotle

#!/usr/bin/perl use warnings; use strict; use Sys::Mmap; my $mmap; #open( FH, '<:mmap',"$0" ) open( FH, "< $0" ) or die "Couldn't open 'file': $!\n"; my $smaddress = mmap( $mmap, 0, PROT_READ, MAP_SHARED, FH ) or die "mmap error: $!\n"; print "$smaddress\n\n$mmap\n\nCheck ipcs -m and hit enter\n\n"; <>; munmap($mmap) or die "mmunmap error: $!\n"; close(FH) or die "Couldn't close 'file': $!\n";

I'm not really a human, but I play one on earth. flash japh

In reply to Mmap question by zentara

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found