I like your style, but it's not quite right:
$ echo /proc/[0-9]/status | wc
1 7 105
$ echo /proc/[1-9]*/status | wc
1 483 8778
It also will sporadically print error messages due to all the race conditions. Here's my stab at it: $ cat dumbps
#!/bin/sh
case $# in
1)
;;
*)
echo "Usage: dumbps user" >&2
exit 2
;;
esac
2>&- find /proc -mindepth 2 -maxdepth 2 -type f -name status -user "$1" | awk '{
while ((getline li < $0) > 0) {
if (li ~ /^Name:/) {
split($0, fn, "/")
print fn[3], substr(li, 6)
break
}
}
close($0)
}'
$ ./dumbps "$USER" | grep -w 'bash$'
1616678 bash
$ ./dumbps 0 | grep -w 'systemd$'
1 systemd
$
It's pretty fast too: $ ls -ld /proc/[1-9]*/status | awk '$3 == "root"' | wc
445 4005 29367
$ time ./dumbps >/dev/null
Usage: dumdps user
real 0m0.001s
user 0m0.000s
sys 0m0.001s
$