.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IPC::Shareable 3pm" .TH IPC::Shareable 3pm "2022-10-15" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" IPC::Shareable \- Use shared memory backed variables across processes .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use IPC::Shareable qw(:lock); \& \& my $href = IPC::Shareable\->new(%options); \& \& # ...or \& \& tie SCALAR, \*(AqIPC::Shareable\*(Aq, OPTIONS; \& tie ARRAY, \*(AqIPC::Shareable\*(Aq, OPTIONS; \& tie HASH, \*(AqIPC::Shareable\*(Aq, OPTIONS; \& \& tied(VARIABLE)\->lock; \& tied(VARIABLE)\->unlock; \& \& tied(VARIABLE)\->lock(LOCK_SH|LOCK_NB) \& or print "Resource unavailable\en"; \& \& my $segment = tied(VARIABLE)\->seg; \& my $semaphore = tied(VARIABLE)\->sem; \& \& tied(VARIABLE)\->remove; \& \& IPC::Shareable::clean_up; \& IPC::Shareable::clean_up_all; \& IPC::Shareable::clean_up_protected; \& \& # Ensure only one instance of a script can be run at any time \& \& IPC::Shareable\->singleton(\*(AqUNIQUE SCRIPT LOCK STRING\*(Aq); \& \& # Get the actual IPC::Shareable tied object \& \& my $knot = tied(VARIABLE); # Dereference first if using a tied reference .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" IPC::Shareable allows you to tie a variable to shared memory making it easy to share the contents of that variable with other Perl processes and scripts. .PP Scalars, arrays, hashes and even objects can be tied. The variable being tied may contain arbitrarily complex data structures \- including references to arrays, hashes of hashes, etc. .PP The association between variables in distinct processes is provided by \&\s-1GLUE\s0 (aka \*(L"key\*(R"). This is any arbitrary string or integer that serves as a common identifier for data across process space. Hence the statement: .PP .Vb 1 \& tie my $scalar, \*(AqIPC::Shareable\*(Aq, { key => \*(AqGLUE STRING\*(Aq, create => 1 }; .Ve .PP \&...in program one and the statement .PP .Vb 1 \& tie my $variable, \*(AqIPC::Shareable\*(Aq, { key => \*(AqGLUE STRING\*(Aq }; .Ve .PP \&...in program two will create and bind \f(CW$scalar\fR the shared memory in program one and bind it to \f(CW$variable\fR in program two. .PP There is no pre-set limit to the number of processes that can bind to data; nor is there a pre-set limit to the complexity of the underlying data of the tied variables. The amount of data that can be shared within a single bound variable is limited by the system's maximum size for a shared memory segment (the exact value is system-dependent). .PP The bound data structures are all linearized (using Raphael Manfredi's Storable module or optionally \s-1JSON\s0) before being slurped into shared memory. Upon retrieval, the original format of the data structure is recovered. Semaphore flags can be used for locking data between competing processes. .SH "OPTIONS" .IX Header "OPTIONS" Options are specified by passing a reference to a hash as the third argument to the \f(CW\*(C`tie()\*(C'\fR function that enchants a variable. .PP The following fields are recognized in the options hash: .SS "key" .IX Subsection "key" \&\fBkey\fR is the \s-1GLUE\s0 that is a direct reference to the shared memory segment that's to be tied to the variable. .PP If this option is missing, we'll default to using \f(CW\*(C`IPC_PRIVATE\*(C'\fR. This default key will not allow sharing of the variable between processes. .PP Default: \fB\s-1IPC_PRIVATE\s0\fR .SS "create" .IX Subsection "create" \&\fBcreate\fR is used to control whether the process creates a new shared memory segment or not. If \fBcreate\fR is set to a true value, IPC::Shareable will create a new binding associated with \s-1GLUE\s0 as needed. If \fBcreate\fR is false, IPC::Shareable will not attempt to create a new shared memory segment associated with \s-1GLUE.\s0 In this case, a shared memory segment associated with \s-1GLUE\s0 must already exist or we'll \f(CW\*(C`croak()\*(C'\fR. .PP Defult: \fBfalse\fR .SS "exclusive" .IX Subsection "exclusive" If \fBexclusive\fR field is set to a true value, we will \f(CW\*(C`croak()\*(C'\fR if the data binding associated with \s-1GLUE\s0 already exists. If set to a false value, calls to \&\f(CW\*(C`tie()\*(C'\fR will succeed even if a shared memory segment associated with \s-1GLUE\s0 already exists. .PP See \*(L"graceful\*(R" for a silent, non-exception exit if a second process attempts to obtain an in-use \f(CW\*(C`exclusive\*(C'\fR segment. .PP Default: \fBfalse\fR .SS "graceful" .IX Subsection "graceful" If \fBexclusive\fR is set to a true value, we normally \f(CW\*(C`croak()\*(C'\fR if a second process attempts to obtain the same shared memory segment. Set \fBgraceful\fR to true and we'll \f(CW\*(C`exit\*(C'\fR silently and gracefully. This option does nothing if \f(CW\*(C`exclusive\*(C'\fR isn't set. .PP Useful for ensuring only a single process is running at a time. .PP Default: \fBfalse\fR .SS "warn" .IX Subsection "warn" When set to a true value, \fBgraceful\fR will output a warning if there are process collisions. .PP Default: \fBfalse\fR .SS "mode" .IX Subsection "mode" The \fBmode\fR argument is an octal number specifying the access permissions when a new data binding is being created. These access permission are the same as file access permissions in that \f(CW0666\fR is world readable, \f(CW0600\fR is readable only by the effective \s-1UID\s0 of the process creating the shared variable, etc. .PP Default: \fB0666\fR (world read and writeable) .SS "size" .IX Subsection "size" This field may be used to specify the size of the shared memory segment allocated. .PP The maximum size we allow by default is ~1GB. See the \*(L"limit\*(R" option to override this default. .PP Default: \f(CW\*(C`IPC::Shareable::SHM_BUFSIZ()\*(C'\fR (ie. \fB65536\fR) .SS "protected" .IX Subsection "protected" If set, the \f(CW\*(C`clean_up()\*(C'\fR and \f(CW\*(C`clean_up_all()\*(C'\fR routines will not remove the segments or semaphores related to the tied object. .PP Set this to a specific integer so we can pass the value to any child objects created under the main one. .PP To clean up protected objects, call \&\f(CW\*(C`(tied %object)\->clean_up_protected(integer)\*(C'\fR, where 'integer' is the value you set the \f(CW\*(C`protected\*(C'\fR option to. You can call this cleanup routine in the script you created the segment, or anywhere else, at any time. .PP Default: \fB0\fR .SS "limit" .IX Subsection "limit" This field will allow you to set a segment size larger than the default maximum which is 1,073,741,824 bytes (approximately 1 \s-1GB\s0). If set, we will \&\f(CW\*(C`croak()\*(C'\fR if a size specified is larger than the maximum. If it's set to a false value, we'll \f(CW\*(C`croak()\*(C'\fR if you send in a size larger than the total system \s-1RAM.\s0 .PP Default: \fBtrue\fR .SS "destroy" .IX Subsection "destroy" If set to a true value, the shared memory segment underlying the data binding will be removed when the process that initialized the shared memory segment exits (gracefully)[1]. .PP Only those memory segments that were created by the current process will be removed. .PP Use this option with care. In particular you should not use this option in a program that will fork after binding the data. On the other hand, shared memory is a finite resource and should be released if it is not needed. .PP \&\fB\s-1NOTE\s0\fR: If the segment was created with its \*(L"protected\*(R" attribute set, it will not be removed upon program completion, even if \f(CW\*(C`destroy\*(C'\fR is set. .PP Default: \fBfalse\fR .SS "tidy" .IX Subsection "tidy" For long running processes, set this to a true value to clean up unneeded segments from nested data structures. Comes with a slight performance hit. .PP Default: \fBfalse\fR .SS "serializer" .IX Subsection "serializer" By default, we use Storable as the data serializer when writing to or reading from the shared memory segments we create. For cross-platform and cross-language purposes, you can optionally use \s-1JSON\s0 for this task. .PP Send in either \f(CW\*(C`json\*(C'\fR or \f(CW\*(C`storable\*(C'\fR as the value to use the respective serializer. .PP Default: \fBstorable\fR .SS "Default Option Values" .IX Subsection "Default Option Values" Default values for options are: .PP .Vb 12 \& key => IPC_PRIVATE, # 0 \& create => 0, \& exclusive => 0, \& mode => 0666, \& size => IPC::Shareable::SHM_BUFSIZ(), # 65536 \& protected => 0, \& limit => 1, \& destroy => 0, \& graceful => 0, \& warn => 0, \& tidy => 0, \& serializer => \*(Aqstorable\*(Aq, .Ve .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Instantiates and returns a reference to a hash backed by shared memory. .PP .Vb 1 \& my $href = IPC::Shareable\->new(key => "testing", create => 1); \& \& $href=>{a} = 1; \& \& # Call tied() on the dereferenced variable to access object methods \& # and information \& \& tied(%$href)\->ipcs; .Ve .PP Parameters: .PP Hash, Optional: See the \*(L"\s-1OPTIONS\*(R"\s0 section for a list of all available options. Most often, you'll want to send in the \fBkey\fR and \fBcreate\fR options. .PP It is possible to get a reference to an array or scalar as well. Simply send in either \f(CW\*(C`var = > \*(AqARRAY\*(Aq\*(C'\fR or \f(CW\*(C`var => \*(AqSCALAR\*(Aq\*(C'\fR to do so. .PP Return: A reference to a hash (or array or scalar) which is backed by shared memory. .ie n .SS "singleton($glue, $warn)" .el .SS "singleton($glue, \f(CW$warn\fP)" .IX Subsection "singleton($glue, $warn)" Class method that ensures that only a single instance of a script can be run at any given time. .PP Parameters: .PP .Vb 1 \& $glue .Ve .PP Mandatory, String: The key/glue that identifies the shared memory segment. .PP .Vb 1 \& $warn .Ve .PP Optional, Bool: Send in a true value to have subsequent processes throw a warning that there's been a shared memory violation and that it will exit. .PP Default: \fBfalse\fR .SS "ipcs" .IX Subsection "ipcs" Returns the number of instantiated shared memory segments that currently exist on the system. This isn't precise; it simply does a \f(CW\*(C`wc \-l\*(C'\fR line count on your system's \f(CW\*(C`ipcs \-m\*(C'\fR call. It is guaranteed though to produce reliable results. .PP Return: Integer .SS "lock($flags)" .IX Subsection "lock($flags)" Obtains a lock on the shared memory. \f(CW$flags\fR specifies the type of lock to acquire. If \f(CW$flags\fR is not specified, an exclusive read/write lock is obtained. Acceptable values for \f(CW$flags\fR are the same as for the \f(CW\*(C`flock()\*(C'\fR system call. .PP Returns \f(CW\*(C`true\*(C'\fR on success, and \f(CW\*(C`undef\*(C'\fR on error. For non-blocking calls (see below), the method returns \f(CW0\fR if it would have blocked. .PP Obtain an exclusive lock like this: .PP .Vb 1 \& tied(%var)\->lock(LOCK_EX); # same as default .Ve .PP Only one process can hold an exclusive lock on the shared memory at a given time. .PP Obtain a shared (read) lock: .PP .Vb 1 \& tied(%var)\->lock(LOCK_SH); .Ve .PP Multiple processes can hold a shared (read) lock at a given time. If a process attempts to obtain an exclusive lock while one or more processes hold shared locks, it will be blocked until they have all finished. .PP Either of the locks may be specified as non-blocking: .PP .Vb 2 \& tied(%var)\->lock( LOCK_EX|LOCK_NB ); \& tied(%var)\->lock( LOCK_SH|LOCK_NB ); .Ve .PP A non-blocking lock request will return \f(CW0\fR if it would have had to wait to obtain the lock. .PP Note that these locks are advisory (just like flock), meaning that all cooperating processes must coordinate their accesses to shared memory using these calls in order for locking to work. See the \f(CW\*(C`flock()\*(C'\fR call for details. .PP Locks are inherited through forks, which means that two processes actually can possess an exclusive lock at the same time. Don't do that. .PP The constants \f(CW\*(C`LOCK_EX\*(C'\fR, \f(CW\*(C`LOCK_SH\*(C'\fR, \f(CW\*(C`LOCK_NB\*(C'\fR, and \f(CW\*(C`LOCK_UN\*(C'\fR are available for import using any of the following export tags: .PP .Vb 3 \& use IPC::Shareable qw(:lock); \& use IPC::Shareable qw(:flock); \& use IPC::Shareable qw(:all); .Ve .PP Or, just use the flock constants available in the Fcntl module. .PP See \*(L"\s-1LOCKING\*(R"\s0 for further details. .SS "unlock" .IX Subsection "unlock" Removes a lock. Takes no parameters, returns \f(CW\*(C`true\*(C'\fR on success. .PP This is equivalent of calling \f(CW\*(C`shlock(LOCK_UN)\*(C'\fR. .PP See \*(L"\s-1LOCKING\*(R"\s0 for further details. .SS "seg" .IX Subsection "seg" Called on either the tied variable or the tie object, returns the shared memory segment object currently in use. .SS "sem" .IX Subsection "sem" Called on either the tied variable or the tie object, returns the semaphore object related to the memory segment currently in use. .SS "attributes" .IX Subsection "attributes" Retrieves the list of attributes that drive the IPC::Shareable object. .PP Parameters: .PP .Vb 1 \& $attribute .Ve .PP Optional, String: The name of the attribute. If sent in, we'll return the value of this specific attribute. Returns \f(CW\*(C`undef\*(C'\fR if the attribute isn't found. .PP Attributes are the \f(CW\*(C`OPTIONS\*(C'\fR that were used to create the object. .PP Returns: A hash reference of all attributes if \f(CW$attributes\fR isn't sent in, the value of the specific attribute if it is. .SS "global_register" .IX Subsection "global_register" Returns a hash reference of hashes of all in-use shared memory segments across all processes. The key is the memory segment \s-1ID,\s0 and the value is the segment and semaphore objects. .SS "process_register" .IX Subsection "process_register" Returns a hash reference of hashes of all in-use shared memory segments created by the calling process. The key is the memory segment \s-1ID,\s0 and the value is the segment and semaphore objects. .SH "LOCKING" .IX Header "LOCKING" IPC::Shareable provides methods to implement application-level advisory locking of the shared data structures. These methods are called \f(CW\*(C`lock()\*(C'\fR and \f(CW\*(C`unlock()\*(C'\fR. To use them you must first get the object underlying the tied variable, either by saving the return value of the original call to \f(CW\*(C`tie()\*(C'\fR or by using the built-in \f(CW\*(C`tied()\*(C'\fR function. .PP To lock and subsequently unlock a variable, do this: .PP .Vb 1 \& my $knot = tie my %hash, \*(AqIPC::Shareable\*(Aq, { %options }; \& \& $knot\->lock; \& $hash{a} = \*(Aqfoo\*(Aq; \& $knot\->unlock; .Ve .PP or equivalently, if you've decided to throw away the return of \f(CW\*(C`tie()\*(C'\fR: .PP .Vb 1 \& tie my %hash, \*(AqIPC::Shareable\*(Aq, { %options }; \& \& tied(%hash)\->lock; \& $hash{a} = \*(Aqfoo\*(Aq; \& tied(%hash)\->unlock; .Ve .PP This will place an exclusive lock on the data of \f(CW$scalar\fR. You can also get shared locks or attempt to get a lock without blocking. .PP IPC::Shareable makes the constants \f(CW\*(C`LOCK_EX\*(C'\fR, \f(CW\*(C`LOCK_SH\*(C'\fR, \f(CW\*(C`LOCK_UN\*(C'\fR, and \&\f(CW\*(C`LOCK_NB\*(C'\fR exportable to your address space with the export tags \f(CW\*(C`:lock\*(C'\fR, \&\f(CW\*(C`:flock\*(C'\fR, or \f(CW\*(C`:all\*(C'\fR. The values should be the same as the standard \f(CW\*(C`flock\*(C'\fR option arguments. .PP .Vb 6 \& if (tied(%hash)\->lock(LOCK_SH|LOCK_NB)){ \& print "The value is $hash{a}\en"; \& tied(%hash)\->unlock; \& } else { \& print "Another process has an exclusive lock.\en"; \& } .Ve .PP If no argument is provided to \f(CW\*(C`lock\*(C'\fR, it defaults to \f(CW\*(C`LOCK_EX\*(C'\fR. .PP There are some pitfalls regarding locking and signals about which you should make yourself aware; these are discussed in \*(L"\s-1NOTES\*(R"\s0. .PP Note that in the background, we perform lock optimization when reading and writing to the shared storage even if the advisory locks aren't being used. .PP Using the advisory locks can speed up processes that are doing several writes/ reads at the same time. .SH "DESTRUCTION" .IX Header "DESTRUCTION" \&\fBperl\fR\|(1) will destroy the object underlying a tied variable when then tied variable goes out of scope. Unfortunately for IPC::Shareable, this may not be desirable: other processes may still need a handle on the relevant shared memory segment. .PP IPC::Shareable therefore provides several options to control the timing of removal of shared memory segments. .SS "destroy Option" .IX Subsection "destroy Option" As described in \*(L"\s-1OPTIONS\*(R"\s0, specifying the \fBdestroy\fR option when \&\f(CW\*(C`tie()\*(C'\fRing a variable coerces IPC::Shareable to remove the underlying shared memory segment when the process calling \f(CW\*(C`tie()\*(C'\fR exits gracefully. .PP \&\fB\s-1NOTE\s0\fR: The destruction is handled in an \f(CW\*(C`END\*(C'\fR block. Only those memory segments that are tied to the current process will be removed. .PP \&\fB\s-1NOTE\s0\fR: If the segment was created with its \*(L"protected\*(R" attribute set, it will not be removed in the \f(CW\*(C`END\*(C'\fR block, even if \f(CW\*(C`destroy\*(C'\fR is set. .SS "remove" .IX Subsection "remove" .Vb 1 \& tied($var)\->remove; \& \& # or \& \& $knot\->remove; .Ve .PP Calling \f(CW\*(C`remove()\*(C'\fR on the object underlying a \f(CW\*(C`tie()\*(C'\fRd variable removes the associated shared memory segments. The segment is removed irrespective of whether it has the \fBdestroy\fR option set or not and irrespective of whether the calling process created the segment. .SS "clean_up" .IX Subsection "clean_up" .Vb 1 \& IPC::Shareable\->clean_up; \& \& # or \& \& tied($var)\->clean_up; \& \& # or \& \& $knot\->clean_up; .Ve .PP This is a class method that provokes IPC::Shareable to remove all shared memory segments created by the process. Segments not created by the calling process are not removed. .PP This method will not clean up segments created with the \f(CW\*(C`protected\*(C'\fR option. .SS "clean_up_all" .IX Subsection "clean_up_all" .Vb 1 \& IPC::Shareable\->clean_up_all; \& \& # or \& \& tied($var)\->clean_up_all; \& \& # or \& \& $knot\->clean_up_all .Ve .PP This is a class method that provokes IPC::Shareable to remove all shared memory segments encountered by the process. Segments are removed even if they were not created by the calling process. .PP This method will not clean up segments created with the \f(CW\*(C`protected\*(C'\fR option. .SS "clean_up_protected($protect_key)" .IX Subsection "clean_up_protected($protect_key)" If a segment is created with the \f(CW\*(C`protected\*(C'\fR option, it, nor its children will be removed during calls of \f(CW\*(C`clean_up()\*(C'\fR or \f(CW\*(C`clean_up_all()\*(C'\fR. .PP When setting \*(L"protected\*(R", you specified a lock key integer. When calling this method, you must send that integer in as a parameter so we know which segments to clean up. .PP .Vb 1 \& my $protect_key = 93432; \& \& IPC::Shareable\->clean_up_protected($protect_key); \& \& # or \& \& tied($var)\->clean_up_protected($protect_key; \& \& # or \& \& $knot\->clean_up_protected($protect_key) .Ve .PP Parameters: .PP .Vb 1 \& $protect_key .Ve .PP Mandatory, Integer: The integer protect key you assigned wit the \f(CW\*(C`protected\*(C'\fR option .SH "RETURN VALUES" .IX Header "RETURN VALUES" Calls to \f(CW\*(C`tie()\*(C'\fR that try to implement IPC::Shareable will return an instance of \f(CW\*(C`IPC::Shareable\*(C'\fR on success, and \f(CW\*(C`undef\*(C'\fR otherwise. .SH "AUTHOR" .IX Header "AUTHOR" Benjamin Sugars .SH "MAINTAINED BY" .IX Header "MAINTAINED BY" Steve Bertrand .SH "NOTES" .IX Header "NOTES" .SS "Footnotes from the above sections" .IX Subsection "Footnotes from the above sections" .IP "1." 4 If the process has been smoked by an untrapped signal, the binding will remain in shared memory. If you're cautious, you might try: .Sp .Vb 6 \& $SIG{INT} = \e&catch_int; \& sub catch_int { \& die; \& } \& ... \& tie $variable, IPC::Shareable, { key => \*(AqGLUE\*(Aq, create => 1, \*(Aqdestroy\*(Aq => 1 }; .Ve .Sp which will at least clean up after your user hits CTRL-C because IPC::Shareable's \s-1END\s0 method will be called. Or, maybe you'd like to leave the binding in shared memory, so subsequent process can recover the data... .SS "General Notes" .IX Subsection "General Notes" .IP "o" 4 .IX Item "o" When using \f(CW\*(C`lock()\*(C'\fR to lock a variable, be careful to guard against signals. Under normal circumstances, \f(CW\*(C`IPC::Shareable\*(C'\fR's \f(CW\*(C`END\*(C'\fR method unlocks any locked variables when the process exits. However, if an untrapped signal is received while a process holds an exclusive lock, \&\f(CW\*(C`END\*(C'\fR will not be called and the lock may be maintained even though the process has exited. If this scares you, you might be better off implementing your own locking methods. .Sp One advantage of using \f(CW\*(C`flock\*(C'\fR on some known file instead of the locking implemented with semaphores in \f(CW\*(C`IPC::Shareable\*(C'\fR is that when a process dies, it automatically releases any locks. This only happens with \f(CW\*(C`IPC::Shareable\*(C'\fR if the process dies gracefully. .Sp The alternative is to attempt to account for every possible calamitous ending for your process (robust signal handling in Perl is a source of much debate, though it usually works just fine) or to become familiar with your system's tools for removing shared memory and semaphores. This concern should be balanced against the significant performance improvements you can gain for larger data structures by using the locking mechanism implemented in IPC::Shareable. .IP "o" 4 .IX Item "o" There is a program called \f(CW\*(C`ipcs\*(C'\fR(1/8) (and \f(CW\*(C`ipcrm\*(C'\fR(1/8)) that is available on at least Solaris and Linux that might be useful for cleaning moribund shared memory segments or semaphore sets produced by bugs in either IPC::Shareable or applications using it. .Sp Examples: .Sp .Vb 1 \& # List all semaphores and memory segments in use on the system \& \& ipcs \-a \& \& # List all memory segments and semaphores along with each one\*(Aqs associated process ID \& \& ipcs \-ap \& \& # List just the shared memory segments \& \& ipcs \-m \& \& # List the details of an individual memory segment \& \& ipcs \-i 12345678 \& \& # Remove *all* semaphores and memory segments \& \& ipcrm \-a .Ve .IP "o" 4 .IX Item "o" This version of IPC::Shareable does not understand the format of shared memory segments created by versions prior to \f(CW0.60\fR. If you try to tie to such segments, you will get an error. The only work around is to clear the shared memory segments and start with a fresh set. .IP "o" 4 .IX Item "o" Iterating over a hash causes a special optimization if you have not obtained a lock (it is better to obtain a read (or write) lock before iterating over a hash tied to IPC::Shareable, but we attempt this optimization if you do not). .Sp For tied hashes, the \f(CW\*(C`fetch\*(C'\fR/\f(CW\*(C`thaw\*(C'\fR operation is performed when the first key is accessed. Subsequent key and and value accesses are done without accessing shared memory. Doing an assignment to the hash or fetching another value between key accesses causes the hash to be replaced from shared memory. The state of the iterator in this case is not defined by the Perl documentation. Caveat Emptor. .SH "CREDITS" .IX Header "CREDITS" Thanks to all those with comments or bug fixes, especially .PP .Vb 10 \& Maurice Aubrey \& Stephane Bortzmeyer \& Doug MacEachern \& Robert Emmery \& Mohammed J. Kabir \& Terry Ewing \& Tim Fries \& Joe Thomas \& Paul Makepeace \& Raphael Manfredi \& Lee Lindley \& Dave Rolsky \& Steve Bertrand .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" perltie, Storable, \f(CW\*(C`shmget\*(C'\fR, \f(CW\*(C`ipcs\*(C'\fR, \f(CW\*(C`ipcrm\*(C'\fR and other SysV \s-1IPC\s0 manual pages.