forked from schacon/perl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perl 3.0 patch #32 patch #29, continued
See patch #29.
- Loading branch information
Larry Wall
committed
Oct 16, 1990
1 parent
c2ab57d
commit d9d8d8d
Showing
24 changed files
with
974 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/perl | ||
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' | ||
if 0; | ||
|
||
require 'sys/ipc.ph'; | ||
require 'sys/msg.ph'; | ||
|
||
$| = 1; | ||
|
||
$mode = shift; | ||
die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/; | ||
$send = ($mode eq "s"); | ||
|
||
$id = msgget(0x1234, ($send ? 0 : &IPC_CREAT) | 0644); | ||
die "Can't get message queue: $!\n" unless defined($id); | ||
print "message queue id: $id\n"; | ||
|
||
if ($send) { | ||
while (<STDIN>) { | ||
chop; | ||
unless (msgsnd($id, pack("LA*", $., $_), 0)) { | ||
die "Can't send message: $!\n"; | ||
} | ||
} | ||
} | ||
else { | ||
$SIG{'INT'} = $SIG{'QUIT'} = "leave"; | ||
for (;;) { | ||
unless (msgrcv($id, $_, 512, 0, 0)) { | ||
die "Can't receive message: $!\n"; | ||
} | ||
($type, $message) = unpack("La*", $_); | ||
printf "[%d] %s\n", $type, $message; | ||
} | ||
} | ||
|
||
&leave; | ||
|
||
sub leave { | ||
if (!$send) { | ||
$x = msgctl($id, &IPC_RMID, 0); | ||
if (!defined($x) || $x < 0) { | ||
die "Can't remove message queue: $!\n"; | ||
} | ||
} | ||
exit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/perl | ||
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' | ||
if 0; | ||
|
||
require 'sys/ipc.ph'; | ||
require 'sys/msg.ph'; | ||
|
||
$| = 1; | ||
|
||
$mode = shift; | ||
die "usage: ipcmsg {r|s}\n" unless $mode =~ /^[rs]$/; | ||
$signal = ($mode eq "s"); | ||
|
||
$id = semget(0x1234, 1, ($signal ? 0 : &IPC_CREAT) | 0644); | ||
die "Can't get semaphore: $!\n" unless defined($id); | ||
print "semaphore id: $id\n"; | ||
|
||
if ($signal) { | ||
while (<STDIN>) { | ||
print "Signalling\n"; | ||
unless (semop($id, 0, pack("sss", 0, 1, 0))) { | ||
die "Can't signal semaphore: $!\n"; | ||
} | ||
} | ||
} | ||
else { | ||
$SIG{'INT'} = $SIG{'QUIT'} = "leave"; | ||
for (;;) { | ||
unless (semop($id, 0, pack("sss", 0, -1, 0))) { | ||
die "Can't wait for semaphore: $!\n"; | ||
} | ||
print "Unblocked\n"; | ||
} | ||
} | ||
|
||
&leave; | ||
|
||
sub leave { | ||
if (!$signal) { | ||
$x = semctl($id, 0, &IPC_RMID, 0); | ||
if (!defined($x) || $x < 0) { | ||
die "Can't remove semaphore: $!\n"; | ||
} | ||
} | ||
exit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/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 message queue: $!\n" unless defined($id); | ||
print "message queue 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.