Here is one of my web log entries, perhaps from my Yakkity Yak page, What's New page, or one of my Astounding Adventures from my Geocaching section:

Jail ps - Or jps
Thursday, 18 August 2005 10:34 AM MDT
Yakkity Yak
Super Geeky Post Alert! Don't say I didn't warn you! *grin*

In administering FreeBSD servers, in particular using FreeBSD jails to encapsulate various processes and/or services, I've often wished for a ps command to list all processes within a particular jail. Now with FreeBSD 5's useful jls command to list all jails on a host, and also jexec which allows one to attach to an existing jail and execute a command within it, it's as easy as whipping up a quick alias or shell script to get a list of processes within a particular jail.

Here's my solution, a shell script I named jps for ps within a jail. (Of course it requires that the ps command be present within the jail and fully functional.)


#!/bin/sh
JID=$1
ISNUM=`expr "${JID}" : '^[0-9]*$'`
if [ -z "${JID}" -o "x${ISNUM}" = "x0" ]; then
echo "Usage: $0 <jail_ID> [<args_to_ps> ...]"
exit 1
fi
shift
jexec $JID /bin/ps $@


Of course it won't work on FreeBSD 4.x hosts, but...