1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/perl -w use Proc:rocessTable; use strict; # get the process name my $name = shift @ARGV or die "You must provide a process name"; # get the PID to process my $pid = get_pid ($name); # if we got a PID... if (defined $pid) { kill 'USR1', $pid or die "$pid - $!\n"; } else # start a new process { system("$name &"); } # find the PID from a process table, based on a name sub get_pid { my $name = shift @_; my $table = new Proc:rocessTable; foreach my $p (@{$table->table}) { # this filters out getem.pl itself return $p->pid if (defined $p->cmndline && $p->cmndline !~ /perl/ && $p->cmndline =~ /^$name/); } return undef; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |