Skip to content

Instantly share code, notes, and snippets.

@smly
Created July 16, 2011 10:53
Show Gist options
  • Select an option

  • Save smly/1086258 to your computer and use it in GitHub Desktop.

Select an option

Save smly/1086258 to your computer and use it in GitHub Desktop.
IPC using shared memory
#!/usr/bin/perl -w
use strict;
use warnings;
use IPC::Shareable;
my $glue = 'access_counter';
my %options = (
create => 'yes',
exclusive => 0,
mode => 0644,
destroy => 0,
);
my $counter;
eval {
tie my $shm_counter, 'IPC::Shareable', $glue, { %options };
(tied $shm_counter)->shlock;
$counter = ++$shm_counter;
(tied $shm_counter)->shunlock;
#(tied $shm_counter)->remove;
};
print "$counter\n";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment