#!/bin/bash

set -eu

out=$(dirname $0)/monitor.log
parent=$1

recurse ()
{
    echo $1
    for child in $(ps -o pid= --ppid $1)
    do
        recurse $child
    done
}

while sleep 30
do
    date +"%F-%T" >> ${out}
    ps o cputimes=,vsz=,rss=,args= --sort=-vsz p $(recurse ${parent}) | head -1 >> ${out}
    free >> ${out}
    echo >> ${out}
done
