#!/usr/bin/bash

if [ -f /run/httpd/httpd.pid ]; then
  PIDFILE=/run/httpd/httpd.pid
elif [ -f /var/run/httpd/httpd.pid ]; then
  PIDFILE=/var/run/httpd/httpd.pid
else
  echo "No pidfile $PIDFILE."
fi

MASTER_PID=`cat $PIDFILE`
N=${1:-20}
echo "Killing $N httpd processes..."
#pgrep httpd | grep -v "^${MASTER_PID}"'$' | tail -$N | xargs kill -9
pgrep -P $MASTER_PID | tail -$N | xargs kill -9
sleep 0.1
L=`pgrep -P $MASTER_PID | wc -l`
echo "$L httpd processes left."
