IPC::SharedMem(3perl)
π NAME π
IPC::SharedMem β the SysV Shared Memory IPC object class, bestie. It's giving "shared memory but make it an object." Periodt.
β¨ SYNOPSIS β¨
use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR);
use IPC::SharedMem;
$shm = IPC::SharedMem->new(IPC_PRIVATE, 8, S_IRWXU);
$shm->write(pack("S", 4711), 2, 2);
$data = $shm->read(0, 2);
$ds = $shm->stat;
$shm->remove;
π¦ DESCRIPTION π¦
Okay so hear me out: this is a class that gives you an object-based interface to SysV IPC shared memory. That's it, that's the whole vibe. No cap. π
π METHODS π
new ( KEY , SIZE , FLAGS )
Creates a brand new shared memory segment, SIZE bytes big, associated with KEY. A fresh segment gets created when:
KEYis equal toIPC_PRIVATE, orKEYdoesn't already have a shared memory segment associated with it, andFLAGS & IPC_CREATis true.
When a new segment is created, FLAGS is what sets the permissions. β οΈ Now listen, bestie β be careful not to set any flags that your Sys V IPC implementation doesn't allow. On some systems, setting execute bits makes the operations straight-up fail. Not the slay you're looking for. π
id
Returns the shared memory identifier. That's it. Iconic, minimal, does its one job. π
read ( POS, SIZE )
Reads SIZE bytes from the shared memory segment at POS. Returns the string it read, or undef if something went wrong. Heads up: the return value becomes tainted. See shmread.
write ( STRING, POS, SIZE )
Writes SIZE bytes to the shared memory segment at POS. Returns true if it ate, false if there was an error. See shmwrite.
remove
Removes the shared memory segment from the system β or marks it as removed for as long as any processes are still attached to it. She can't leave the group chat until everyone stops typing. π«Ά
is_removed
Returns true if the shared memory segment has been removed or marked for removal. Yes, it's the vibe check for removal status. β¨
stat
Returns an object of type IPC::SharedMem::stat, which is a sub-class of Class::Struct. It's got these fields, and for a description of what they all mean, go check your system documentation (I'm a manual page, not a syscall scholar π§):
uid
gid
cuid
cgid
mode
segsz
lpid
cpid
nattch
atime
dtime
ctime
attach ( [FLAG] )
Permanently attaches to the shared memory segment. Here's the tea: once an IPC::SharedMem object is attached, it uses memread and memwrite instead of shmread and shmwrite to access the shared memory segment. Returns true if it worked, false on error. See shmat(2).
detach
Detaches from the shared memory segment that previously has been attached to. Returns true if success, false on error. See shmdt(2). It's the breakup but make it mutual and clean. πβ‘οΈπ
addr
Returns the address of the shared memory that has been attached to, in a format suitable for use with pack('P'). Returns undef if the shared memory hasn't been attached. No attachment, no address. Them's the rules. π
π SEE ALSO π
IPC::SysVClass::Struct
π AUTHORS π
Marcus Holland-Moritz <mhx@cpan.org>
πΈ COPYRIGHT πΈ
Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz.
Version 1.x, Copyright (c) 1997, Graham Barr.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay bestie that's the whole page, go forth and share your memory responsibly π
perl v5.44.0 Β· 2026-10-17 Β· IPC::SharedMem(3perl) β mwah, slay, bye! π
β¨π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms