From: hadaq Date: Tue, 24 Aug 2010 08:24:09 +0000 (+0000) Subject: New script for cleanup of not killed evtbuild processes and remaining shared mem... X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=3d7bc66f12c8b9ac5cf36b5446664c7e7e5f82f6;p=daqdata.git New script for cleanup of not killed evtbuild processes and remaining shared mem. Sergey. --- diff --git a/disks/cleanup_evtbuild.pl b/disks/cleanup_evtbuild.pl new file mode 100755 index 0000000..f026fd4 --- /dev/null +++ b/disks/cleanup_evtbuild.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl -w + +use strict; +use Data::Dumper; + +#- Kill daq_evtbuild or daq_netmem if remained + +my $pname = "daq_netmem"; +my @out_list = `ps -C $pname`; +&killSoftProcs(\@out_list, $pname); +sleep 1; +@out_list = `ps -C $pname`; +&killHardProcs(\@out_list, $pname); + +$pname = "daq_evtbuild"; +@out_list = `ps -C $pname`; +&killSoftProcs(\@out_list, $pname); +sleep 1; +@out_list = `ps -C $pname`; +&killHardProcs(\@out_list, $pname); + +#- Remove shared memory segments if remained + +my $shm_dir = "/dev/shm"; + +opendir(DIR, $shm_dir) or die "Could not open $shm_dir: $!"; + +my @shm_list = grep(/\w+\.shm/, readdir(DIR)); + +foreach my $shmem (@shm_list){ + my $cmd = "rm $shm_dir/$shmem"; + #print "cmd: $cmd\n"; + system($cmd); +} + +################### END OF MAIN ################### + +sub killSoftProcs() +{ + my ($list_aref, $proc_name) = @_; + + foreach my $line (@$list_aref){ + $line =~ s/^\s+//; # remove leading spaces + if( $line =~ /$proc_name/ ){ + my @items = split( /\s+/, $line ); + my $PID = $items[0]; + + system("kill $PID"); + } + } +} + +sub killHardProcs() +{ + my ($list_aref, $proc_name) = @_; + + foreach my $line (@$list_aref){ + + if( $line =~ /$proc_name/ ){ + $line =~ s/^\s+//; # remove leading spaces + my @items = split( /\s+/, $line ); + + my $PID = $items[0]; + + system("kill -9 $PID"); + } + } +}