Application tools
From PRAGMAgridWIKI
Contents |
[edit]
IPCremover by Tsutomu Ikegami, AIST
[edit]
IPCremover Usage
NAME
ipcremover.pl -- remove shared resources
SYNOPSIS
% ipcremover.pl [-u <user>|-a] [-v]
-u : specify owner of the shared resources to be removed
default: current user
-a : try to remove all the shared resources
-v : output statistics on exit
DESCRIPTION
Ipcremover.pl removes all the shared resources, such as shared
memories, semaphores, and message queues, owned by the current user.
These resources are typically used in the parallel programming.
Different from malloced memories, shared resources are not released
automatically on exit. As a result, it is often the case that the
shared resources are left behind on unexpected abort or crash. Because
the limitation on the shared resources are kept tight on most of the
systems, applications utilizing shared resources stop working if the
abandoned resources are accumulated. This script removes those shared
resources, by using ipcs and ipcrm commands.
OPTIONS
C<-u>
Specifies owner of the resources to be removed. The real UID of
ipcremover.pl is used by default. To remove resources owned by
others, root privilege is required or the permission of the resources
must be set appropriately.
C<-a>
Removes all the shared resources found by "ipcs -a" command. Root
privilege is typically necessary.
C<-v>
Outputs the numbers of the removed resources on exit. The three
numbers are the numbers of shared memories, semaphores, and message
queues, in order.
BUGS
The script can remove only the resources detectable by ipcs command.
Those stealth resources that is not assigned read permission (by
shmctl() systemcall and etc.) are not listed by "ipcs -a", and thus
cannot be removed. (This can be avoided by making a resource list
from /proc/sysvipc/*. The ipcrm command can remove stealth
resources.)
The script is only aware of Linux "ipcs -a" format. It won't work on
BSD machines.
MPICH provides the similar command, "cleanipcs".
AUTHOR
IKEGAMI, Tsutomu, ikegami at ni.aist.go.jp
[edit]
IPCremover script
#!/usr/bin/perl
#
# ipcremover.pl -- Remove shared resources
#
use strict;
use warnings;
our $Verbose;
our $User = getpwuid($<) || $ENV{USER};
while( @ARGV and $ARGV[0] =~ /^-/ ) {
$_ = shift;
/^-v/ and $Verbose = 1, next;
/^-u/ and $User = shift, next;
/^-a/ and $User = undef, next;
/^--/ and last;
die "usage: $0 [-u <user>|-a] [-v]\n";
}
my ($A, @M, @S, @Q);
$ENV{LANG} = "C";
open(IPC, "/usr/bin/ipcs |") or die "Cannot find ipcs command.\n";
while (<IPC>) {
/Shared Memory/ and $A = \@M, next;
/Semaphore Arrays/ and $A = \@S, next;
/Message Queues/ and $A = \@Q, next;
my (undef, $id, $user) = split;
defined($id) && $id =~ /^\d+$/ or next;
if ($User) {
$User eq $user or next;
}
push @$A, $id;
}
my $Command;
for (@M) { $Command .= " -m $_" }
for (@S) { $Command .= " -s $_" }
for (@Q) { $Command .= " -q $_" }
if ($Command) {
system("/usr/bin/ipcrm $Command") == 0 or die "Failed in ipcrm command.\n";
}
$Verbose and printf "%d %d %d\n", scalar(@M), scalar(@S), scalar(@Q);
exit 0;
