2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
11 die "usage: ipcshm {r|s}\n" unless $mode =~ /^[rs]$/;
12 $send = ($mode eq "s");
15 $id = shmget(0x1234, $SIZE, ($send ? 0 : &IPC_CREAT) | 0644);
16 die "Can't get shared memory: $!\n" unless defined($id);
17 print "shared memory id: $id\n";
22 unless (shmwrite($id, pack("La*", length($_), $_), 0, $SIZE)) {
23 die "Can't write to shared memory: $!\n";
28 $SIG{'INT'} = $SIG{'QUIT'} = "leave";
31 unless (shmread($id, $_, 0, $SIZE)) {
32 die "Can't read shared memory: $!\n";
34 $len = unpack("L", $_);
35 $message = substr($_, length(pack("L",0)), $len);
36 printf "[%d] %s\n", $len, $message;
44 $x = shmctl($id, &IPC_RMID, 0);
45 if (!defined($x) || $x < 0) {
46 die "Can't remove shared memory: $!\n";