#!/bin/bash

. /usr/local/lib/labtool.shlib || echo 'Error: labtool.shlib not found!'
trap on_exit EXIT

# "elephant" should not be running
ELEPHANT=elephant

# "hippo" should be niced to the value of HIPPO_NICE
HIPPO=hippo
HIPPO_NICE=5

# make sure we are running on server
check_host "server"


echo -n "* Checking for terminated process... "

if ps -C "$ELEPHANT" &>/dev/null
then
    echo "FAIL"
    echo
    echo "The \"memory hogging\" process is still running."
else
    echo "PASS"
fi


echo -n "* Checking for reniced process... "

HN="$(ps -C "$HIPPO" -o nice= | tr -d '[:space:]')"

if [[ $HN == $HIPPO_NICE ]]
then
    echo "PASS"
else
    echo "FAIL"
    echo
    echo "The \"CPU hogging\" process does not have a priority of ${HIPPO_NICE}."
fi

exit
    
