head	1.2;
access;
symbols
	RELENG_2_2_8_RELEASE:1.1.1.1
	RELENG_2_2_7_RELEASE:1.1.1.1
	RELENG_2_2_6_RELEASE:1.1.1.1
	RELENG_2_2_5_RELEASE:1.1.1.1
	RELENG_2_2_2_RELEASE:1.1.1.1
	RELENG_2_2_1_RELEASE:1.1.1.1
	RELENG_2_2_0_RELEASE:1.1.1.1
	RELENG_2_1_7_RELEASE:1.1.1.1
	RELENG_2_1_6_1_RELEASE:1.1.1.1
	RELENG_2_1_6_RELEASE:1.1.1.1
	RELENG_2_2:1.1.1.1.0.8
	RELENG_2_2_BP:1.1.1.1
	RELENG_2_1_5_RELEASE:1.1.1.1
	RELENG_2_1_0_RELEASE:1.1.1.1
	RELENG_2_1_0:1.1.1.1.0.6
	RELENG_2_1_0_BP:1.1.1.1
	RELENG_2_0_5_RELEASE:1.1.1.1
	RELENG_2_0_5:1.1.1.1.0.4
	RELENG_2_0_5_BP:1.1.1.1
	RELENG_2_0_5_ALPHA:1.1.1.1
	RELEASE_2_0:1.1.1.1
	BETA_2_0:1.1.1.1
	ALPHA_2_0:1.1.1.1.0.2
	perl_4_036_bmake:1.1.1.1
	lwall:1.1.1;
locks; strict;
comment	@# @;


1.2
date	98.09.09.06.49.06;	author markm;	state dead;
branches;
next	1.1;

1.1
date	94.09.10.06.27.48;	author gclarkii;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.09.10.06.27.49;	author gclarkii;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Old Perl is leaving us. Goodbye, faithful friend.
@
text
@#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@@"}'
	if 0;

require 'sys/ipc.ph';
require 'sys/shm.ph';

$| = 1;

$mode = shift;
die "usage: ipcshm {r|s}\n" unless $mode =~ /^[rs]$/;
$send = ($mode eq "s");

$SIZE = 32;
$id = shmget(0x1234, $SIZE, ($send ? 0 : &IPC_CREAT) | 0644);
die "Can't get shared memory: $!\n" unless defined($id);
print "shared memory id: $id\n";

if ($send) {
	while (<STDIN>) {
		chop;
		unless (shmwrite($id, pack("La*", length($_), $_), 0, $SIZE)) {
			die "Can't write to shared memory: $!\n";
		}
	}
}
else {
	$SIG{'INT'} = $SIG{'QUIT'} = "leave";
	for (;;) {
		$_ = <STDIN>;
		unless (shmread($id, $_, 0, $SIZE)) {
			die "Can't read shared memory: $!\n";
		}
		$len = unpack("L", $_);
		$message = substr($_, length(pack("L",0)), $len);
		printf "[%d] %s\n", $len, $message;
	}
}

&leave;

sub leave {
	if (!$send) {
		$x = shmctl($id, &IPC_RMID, 0);
		if (!defined($x) || $x < 0) {
			die "Can't remove shared memory: $!\n";
		}
	}
	exit;
}
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Initial import of Perl 4.046 bmaked

@
text
@@
