#!/bin/sh

PID=$1
UPTIME_FILE=/proc/uptime
STATUS_FILE=/proc/${PID}/statm
PGSZ=4

# first line of csv output
printf "uptime;size;resident;share;text;lib;data;dt"

while [ -e ${STATUS_FILE} ]
do
  set -- $(cat ${UPTIME_FILE})
  UPTIME=${1}
  set -- $(cat ${STATUS_FILE})
  printf "%s;%s;%s;%s;%s;%s;%s;%s\\n" "${UPTIME}" "$((${1} * ${PGSZ}))" "$((${2} * ${PGSZ}))" "$((${3} * ${PGSZ}))" "$((${4} * ${PGSZ}))" "$((${5} * ${PGSZ}))" "$((${6} * ${PGSZ}))" "$((${7} * ${PGSZ}))"
  sleep 1
done

