1IPC::SharedMem(3) User Contributed Perl Documentation IPC::SharedMem(3)
2
3
4
6 IPC::SharedMem - SysV Shared Memory IPC object class
7
9 use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR);
10 use IPC::SharedMem;
11
12 $shm = IPC::SharedMem->new(IPC_PRIVATE, 8, S_IRWXU);
13
14 $shm->write(pack("S", 4711), 2, 2);
15
16 $data = $shm->read(0, 2);
17
18 $ds = $shm->stat;
19
20 $shm->remove;
21
23 A class providing an object based interface to SysV IPC shared memory.
24
26 new ( KEY , SIZE , FLAGS )
27 Creates a new shared memory segment of "SIZE" bytes size associated
28 with "KEY". A new segment is created if
29
30 • "KEY" is equal to "IPC_PRIVATE"
31
32 • "KEY" does not already have a shared memory segment associated
33 with it, and "FLAGS & IPC_CREAT" is true.
34
35 On creation of a new shared memory segment "FLAGS" is used to set
36 the permissions. Be careful not to set any flags that the Sys V
37 IPC implementation does not allow: in some systems setting execute
38 bits makes the operations fail.
39
40 id Returns the shared memory identifier.
41
42 read ( POS, SIZE )
43 Read "SIZE" bytes from the shared memory segment at "POS". Returns
44 the string read, or "undef" if there was an error. The return value
45 becomes tainted. See shmread.
46
47 write ( STRING, POS, SIZE )
48 Write "SIZE" bytes to the shared memory segment at "POS". Returns
49 true if successful, or false if there is an error. See shmwrite.
50
51 remove
52 Remove the shared memory segment from the system or mark it as
53 removed as long as any processes are still attached to it.
54
55 is_removed
56 Returns true if the shared memory segment has been removed or
57 marked for removal.
58
59 stat
60 Returns an object of type "IPC::SharedMem::stat" which is a sub-
61 class of "Class::Struct". It provides the following fields. For a
62 description of these fields see you system documentation.
63
64 uid
65 gid
66 cuid
67 cgid
68 mode
69 segsz
70 lpid
71 cpid
72 nattch
73 atime
74 dtime
75 ctime
76
77 attach ( [FLAG] )
78 Permanently attach to the shared memory segment. When a
79 "IPC::SharedMem" object is attached, it will use memread and
80 memwrite instead of shmread and shmwrite for accessing the shared
81 memory segment. Returns true if successful, or false on error. See
82 shmat(2).
83
84 detach
85 Detach from the shared memory segment that previously has been
86 attached to. Returns true if successful, or false on error. See
87 shmdt(2).
88
89 addr
90 Returns the address of the shared memory that has been attached to
91 in a format suitable for use with pack('P'). Returns "undef" if the
92 shared memory has not been attached.
93
95 IPC::SysV, Class::Struct
96
98 Marcus Holland-Moritz <mhx@cpan.org>
99
101 Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz.
102
103 Version 1.x, Copyright (c) 1997, Graham Barr.
104
105 This program is free software; you can redistribute it and/or modify it
106 under the same terms as Perl itself.
107
108
109
110perl v5.36.0 2023-01-20 IPC::SharedMem(3)