Hacker News new | ask | show | jobs
by imglorp 697 days ago
About as minimal as you can get with pids and command names:

ps(){ (cd /proc;for i in [0-9]*;do echo $i: $(tr '\0' ' ' < $i/cmdline);done); }

1 comments

That forks twice for every iteration of the loop, though: once for the subshell, and again to run `tr`.
Fix:

  ps() { for i in /proc/[0-9]*; do readarray -d '' -t cmdline < "$i/cmdline"; printf "%s: %s\n" "${i#/proc/}" "${cmdline[*]}"; done; }