#!/usr/bin/perl
#
# delete_semaphores.pl: delete leftover semaphores from crashed MPI programs
#
$IPCRM="/usr/bin/ipcrm";
$IPCS="/usr/bin/ipcs";
@SEMAPHORES=`$IPCS -s`;

for ($i = 3; $i < $#SEMAPHORES; $i++) {
  @line = split(' ',$SEMAPHORES[$i]);
  $semid = $line[1];
# print "$semid\n";
  system("$IPCRM sem $semid");
}

@SHMEMSEGS=`$IPCS -m`;

for ($i = 3; $i < $#SHMEMSEGS; $i++) {
  @line = split(' ',$SHMEMSEGS[$i]);
  $shmid = $line[1];
# print "$shmid\n";
  system("$IPCRM shm $shmid");
}
