#!/usr/local/bin/bash # # ps replacement for chrooted environment # # prints out the ACTUAL processes ONLY within the environment present # based on nice(1) values # # Zoidial, Inc. # Eric Thern, eric NOSPAMat zoidial.com # # October 22, 2002 # # # In this case, the chrooted environment is running with: # nice -n 2 chroot /chroot /bin/sh /etc/rc # # and all users have a nice of 12 via /etc/login.conf priority option # # we can assume everything runs as one of these two nices, # this way we can track all processes within this particular chroot. # echo "" echo "This is 'ps' for chrooted environments" echo "Be patient - this is slower than normal ps!" echo "" echo "USER UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND" ps -o user -awwwxl | awk '{if ($7 == 2 || $7 == 12) for (n=1; n <= NF; n++) { if (n <= 13) { ORS = "\t"; print $n;} else {ORS = " "; print $n; }; }; if ($7 == 2 || $7 == 12) print "\n" }'