summaryrefslogtreecommitdiff
path: root/pod/perlipc.pod
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>1998-07-07 05:32:53 +0300
committerGurusamy Sarathy <gsar@cpan.org>1998-07-08 07:12:47 +0000
commit0ade19845bc827615a636e5c073d498c2244ec07 (patch)
treeb25ebb72b2e377b5783ce95110d54bd7c6bfc6c5 /pod/perlipc.pod
parent569536030df0016c037f85e8e6d3ef93f000c47a (diff)
downloadperl-0ade19845bc827615a636e5c073d498c2244ec07.tar.gz
add extension to support SysV IPC
Message-Id: <199807062332.CAA25792@alpha.hut.fi> Subject: [PATCH] 5.004_70: IPC::SysV p4raw-id: //depot/perl@1372
Diffstat (limited to 'pod/perlipc.pod')
-rw-r--r--pod/perlipc.pod37
1 files changed, 20 insertions, 17 deletions
diff --git a/pod/perlipc.pod b/pod/perlipc.pod
index 2348d396c0..59c5ad9f01 100644
--- a/pod/perlipc.pod
+++ b/pod/perlipc.pod
@@ -1306,29 +1306,33 @@ you weren't wanting it to.
Here's a small example showing shared memory usage.
- $IPC_PRIVATE = 0;
- $IPC_RMID = 0;
+ use IPC::SysV qw(IPC_PRIVATE IPC_RMID S_IRWXU S_IRWXG S_IRWXO);
+
$size = 2000;
- $key = shmget($IPC_PRIVATE, $size , 0777 );
- die unless defined $key;
+ $key = shmget(IPC_PRIVATE, $size, S_IRWXU|S_IRWXG|S_IRWXO) || die "$!";
+ print "shm key $key\n";
$message = "Message #1";
- shmwrite($key, $message, 0, 60 ) || die "$!";
- shmread($key,$buff,0,60) || die "$!";
+ shmwrite($key, $message, 0, 60) || die "$!";
+ print "wrote: '$message'\n";
+ shmread($key, $buff, 0, 60) || die "$!";
+ print "read : '$buff'\n";
- print $buff,"\n";
+ # the buffer of shmread is zero-character end-padded.
+ substr($buff, index($buff, "\0")) = '';
+ print "un" unless $buff eq $message;
+ print "swell\n";
- print "deleting $key\n";
- shmctl($key ,$IPC_RMID, 0) || die "$!";
+ print "deleting shm $key\n";
+ shmctl($key, IPC_RMID, 0) || die "$!";
Here's an example of a semaphore:
+ use IPC::SysV qw(IPC_CREAT);
+
$IPC_KEY = 1234;
- $IPC_RMID = 0;
- $IPC_CREATE = 0001000;
- $key = semget($IPC_KEY, $nsems , 0666 | $IPC_CREATE );
- die if !defined($key);
- print "$key\n";
+ $key = semget($IPC_KEY, 10, 0666 | IPC_CREAT ) || die "$!";
+ print "shm key $key\n";
Put this code in a separate file to be run in more than one process.
Call the file F<take>:
@@ -1375,9 +1379,8 @@ Call this file F<give>:
semop($key,$opstring) || die "$!";
The SysV IPC code above was written long ago, and it's definitely
-clunky looking. It should at the very least be made to C<use strict>
-and C<require "sys/ipc.ph">. Better yet, check out the IPC::SysV modules
-on CPAN.
+clunky looking. For a more modern look, see the IPC::SysV module
+which is included with Perl starting from Perl 5.005.
=head1 NOTES