#!/opt/bin/perl # ######################################################################### # # # Program to ensure periodically that only one copy of a program runs # # # ######################################################################### # # # Version 1.0 - Written 03.03.96 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # Configure here the name of the program to monitor: # - absolute path and filename: $program = '/opt/bin/prmonitor'; # - as a regular expression: $pattern = '/opt/bin/prmonitor'; # Some defaults: $version = 'version 1.0'; $self = $0; $self =~ s!^.*/!!; unless (open(PROCESSES, "ps -auxgw|")) { die "$self: can't read from pipe 'ps -auxgw': $!\n"; } while () { chop; ($user,$pid) = split(' '); $command = substr($_,56); if ($command =~ m!$pattern!o) { push(@PID, $pid); } } close(PROCESSES); if (@PID > 1) { foreach $pid (@PID) { system("/bin/kill -9 $pid"); warn "$self: killed process $pid ($command)!\n"; } } if (@PID != 1) { system("/bin/nohup $program >/dev/null 2>$program.log &"); } __END__