What I'm looking for is suggestions as to my kill handling and are there more efficient alternative to parsing ps output??
ps output:
22313 /usr/local/bin/perl -w ./b_mon.pl do 22315 /usr/local/bin/perl -w ./b_server.pl -temail -lny -sa
CODE
#!/usr/local/bin/perl -w #----------------------------------------- # process killer #----------------------------------------- use strict; my %p_table = get_proc(); if (scalar keys %p_table >= 1) { for (keys %p_table) { my $pid = $_; my $msg = "\nPID : $pid : PROCESS :: $p_table{$pid} ::: KILL i +t ??? (y/n) : "; print $msg; while (<STDIN>) { chomp; if ($_ =~ /^y$/i) { my $rc = kill 1, $pid; ($rc) ? print "killed OK\n" : print "didnt kill\n"; last; } elsif ($_ =~ /^n$/i) { last; } else { print $msg; next; } } } } else { print "No perl-ish processes found \n"; } #-------------------------------------------------- # format output from ps into only perl processes #-------------------------------------------------- sub get_proc { my %table; for (`ps -u richardh -o pid,args`) { chomp; if ($_ =~ /perl/) { my @ary = split / /, $_; my $var = shift @ary; unless ($var == $$) { $table{ $var } = join ' ', @ary; } } } return %table; }
In reply to killing child processes by agoth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |