You are here iC Home > Perl > Perl for Sysad's > getpid Process id

Perl

6.6 getpid Process id

20.07.2008
6.5 sslcsr.pl [  up  ] - [ a - z ] - [ search PC ] - [ top ] 6.7 LDAP

getpid

#!/usr/bin/perl
# $Date: 2004/03/22 01:13:00 $ $Revision: 1.2 $
use strict;

my @lines = split /\n/, `ps -axw|grep $ARGV[0]`;

my @dummy = split /\//, $0;
my $SCRIPT_SHORT = $dummy[$#dummy];

my $RUNNING = 0;
my $PID = 0;

foreach (@lines) {
	next if $_ =~ /grep $ARGV[0]/ or $_ =~ /$SCRIPT_SHORT $ARGV[0]/;
	$RUNNING++;
	$PID = $_; $PID += 0;
	print $PID unless $ARGV[1] eq 'status';
	last;
}

if ($ARGV[1] eq 'status') {
	print $RUNNING ? "Running [$PID]" : 'Stopped';
}

Save this script as getpid under /usr/local/bin/.


Usage

getpid {process_name} [status]

getpid smsbox

getpid smsbox status


Advanced search tips
6.5 sslcsr.pl [  up  ] - [ top ] 6.7 LDAP



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi