#!/usr/bin/perl use strict; use warnings; my $cmd='/usr/bin/perl'; my @pids; for my $proc (glob('/proc/*')) { # alle ordner mit zahlen sind prozesse if($proc=~m!/(\d+)$!) { my $pid=$1; # testet ob "exe" vorhanden und die Quelle gleich dem Gesuchten if(-f "$proc/exe" && readlink("$proc/exe") eq $cmd) { push(@pids,$pid); } # kommt der name in die Kommandozeile vor elsif(my $cmdline=slurp("$proc/cmdline")) { push(@pids,$pid) if($cmdline=~m!^\s*\Q$cmd!s); } } } print "$cmd is running as (@pids)\n"; sub slurp { my $file=shift; return eval{local($/,@ARGV)=(undef,$file); <>} }