#!/bin/sh - # # Copyright (C) 2007 Oliver Fromme # All rights reserverd. Standard 2-clause BSD license and disclaimer apply. # # List processes that are running inside a jail. # This is intended to complement the standard jls(8) command. # # Usage: # jps list all jailed processes # jps list only processes in jail . # # Run the jls(8) command to get a list of jails and JIDs. # set -Cefu ME="${0##*/}" export PATH=/bin:/sbin:/usr/bin:/usr/sbin Usage() { cat <<-tac $ME -- List processes that are running inside a jail. This is intended to complement the standard jls(8) command. Usage: $ME [-c] List all jailed processes. $ME [-c] List only processes in jail . Options: -c Include the chroot path of the jail in the output. This requires more processing and is slower, so it is not the default. Run the jls(8) command to get a list of jails and JIDs. tac exit 1 } if [ "x${1:-}" = "x-c" ]; then SHOW_CHROOT=true shift else SHOW_CHROOT=false fi if [ "x${1:-}" = "x--" ]; then shift fi if [ $# -ge 2 ]; then Usage fi if [ $# -eq 1 ]; then case "$1" in ""|*[!0-9]*) Usage ;; esac FILTER='$1=="'$1'"' else FILTER='$1!="0"' fi if $SHOW_CHROOT; then eval $( jls | while read JID J_IP J_HOSTNAME J_PATH; do echo "CHROOT_$JID='$J_PATH'" done ) CHROOT_JID="CHROOT" VT=$(echo -e '\v') ps -axww -o jid,pid,user,command \ | awk '$1!~/[0-9]/||'"$FILTER" \ | while read JID J_PID J_USER J_COMMAND; do eval J_CHROOT=\"\$CHROOT_$JID\" echo "$JID$VT$J_PID$VT$J_USER$VT$J_CHROOT$VT$J_COMMAND" done \ | sort -n \ | rs -c"$VT" -z 0 5 else ps -axww -o jid,pid,user,command \ | awk '$1!~/[0-9]/||'"$FILTER" \ | sort -n fi #--