+pidof supporting -u
authorlace <>
Tue, 24 Jun 2008 17:47:18 +0000 (17:47 +0000)
committerlace <>
Tue, 24 Jun 2008 17:47:18 +0000 (17:47 +0000)
.bashrc

diff --git a/.bashrc b/.bashrc
index 842e954..f00ed6d 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -277,6 +277,25 @@ function cvs {(unset cvs
        cvs $_line $_opts "$@"
        ); }
 function perlrpm { repoquery -q --whatprovides $(for i in "$@";do echo "perl($i)";done|sed -e 's/\//::/g' -e 's/[.]pm//g'); }
        cvs $_line $_opts "$@"
        ); }
 function perlrpm { repoquery -q --whatprovides $(for i in "$@";do echo "perl($i)";done|sed -e 's/\//::/g' -e 's/[.]pm//g'); }
+# `-u' limits the search to $UID.
+function pidof
+{(unset pidof
+  if [ "$1" = "-u" ];then
+    shift
+    local r="$(pidof "$@")"
+    local space=""
+    local p
+    for p in $r;do
+      if grep -q "$(echo -e "^Uid:\t$UID\t")" "/proc/$p/status";then
+       echo -n "${space}$p"
+       space=" "
+      fi
+    done
+    echo
+  else
+    pidof "$@"
+  fi
+)}
 
 ulimit -S -c 0
 set +H
 
 ulimit -S -c 0
 set +H