NAME
SysV::SharedMem - SysV Shared memory made easy
VERSION
Version 0.003
SYNOPSIS
use SysV::SharedMem;
shared_open my $mem, '/path', '+>', size => 4096;
vec($mem, 1, 16) = 34567;
substr $mem, 45, 11, 'Hello World';
This module maps shared memory into a variable that can be read just like any other variable, and it can be written to using standard Perl techniques such as regexps and substr
, as long as they don't change the length of the variable.
METHODS
shared_open($var, $filename, $mode, %options)
Open a shared memory object named $filename
and attach it to $var
. $filename must be the path to an existing file or undef, in which case the key
option is used. $mode
determines the read/write mode. It works the same as in open.
Beyond that it can take a number of optional named arguments:
size
This determines the size of the map. Must be set if a new shared memory object is being created.
perms
This determines the permissions with which the file is created (if $mode is '+>'). Default is 0700.
offset
This determines the offset in the file that is mapped. Default is 0.
key
If
$filename
is undefined this parameter is used as the key to lookup the shared memory segment. It defaults to IPC_PRIVATE, which causes a new, anonymous shared memory segment to be created.id
The project id, used to ensure the key generated from the filename is unique. Only the lower 8 bits are significant and may not be zero. Defaults to 1.
shared_remove($var)
Marks a memory object to be removed. Shared memory has kernel persisence so it has to be explicitly disposed of. One can still use the object after marking it for removal.
shared_stat($var)
Retrieve the properties of the shared memory object. It returns a hashref with these members:
uid
Owner's user ID
gid
Owner's group ID
cuid
Creator's user ID
cgid
Creator's group ID
mode
Read/write permission
segsz
Size of segment in bytes
lpid
Process ID of last shared memory operation
cpid
Process ID of creator
nattch
Number of current attaches
atime
Time of last attachment
dtime
Time of last detachment
ctime
Time of last of control structure
shared_chmod($var, $modebits)
Change the (lower 9) modebits of the shared memory object.
shared_chown($var, $uid, $gid = undef)
Change the owning uid and optionally gid of the shared memory object.
AUTHOR
Leon Timmermans, <leont at cpan.org>
BUGS
Please report any bugs or feature requests to bug-sysv-sharedmem at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SysV-SharedMem. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc SysV::SharedMem
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2010 Leon Timmermans.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.