preload
Oct 07

潛暹鈭 Linux 銝 pidof 隞文臭誑敺瑁銝剔摨pid

OSX 銝行批遣隞歹嗆仿 ps aux | grep XXX 銋臭誑啁詨踝Y憿舐內蝯銝憭銋暹楊

閰西餅 pidof source code 靘蝺刻陌嚗雿蝺其韏瑚XD

撟詨末嗡擃靘鈭 scrpit

冽迨蝭蝔撘蝣潔誑鞈嚗
Shell Script嚗

1
2
#!/bin/sh
ps axc|awk "{if (\$5==\"$1\") print \$1}";

Perl嚗

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
 
@procs = `ps -x`;
 
for $proc (@procs ) {
    if( $proc =~ /\s+(\d+)\s+\S+\s+\S+\s+\S+\s+(\S+)/ ) {
	$pid = $1;
	$name = $2;
	if( $name =~ /$ARGV[0]/ ) {
	    print "$pid ";
	}
    }
}
 
print "\n";

link嚗macosxhints.com – Create a pidof command to find PID numbers easily

Tagged with: