#!/usr/bin/perl -w use strict; use Proc::ProcessTable; my $t1 = new Proc::ProcessTable; my $pid; my $commandline = shift || $0; foreach my $p (@{$t1->table}){ if($p->cmndline =~ /\Q$commandline\E/){ $pid = $p->pid; print "$pid\n"; } } ###################################################