#!/bin/bash

# Copyright (c) 2001-2014, The Ohio State University. All rights
# reserved.
#
# This file is part of the MVAPICH2 software package developed by the
# team members of The Ohio State University's Network-Based Computing
# Laboratory (NBCL), headed by Professor Dhabaleswar K. (DK) Panda.
#
# For detailed copyright and licensing information, please refer to the
# copyright file COPYRIGHT in the top level MVAPICH2 directory.

if [ -z "$USER" ]; then
    USER=$(whoami 2>/dev/null)

    if [ $? = 0 ]; then
	USER_ARG="-U$USER"
    else
	USER_ARG=""
    fi
else
    USER_ARG="-U$USER"
fi

echo
ps $USER_ARG -e -o pid,user,tty,comm:11,pcpu,vsize,bsdstart,cmd |egrep 'PID +USER|mpiexec|mpirun_rsh' |egrep -v 'grep|python'
echo
PID=""

while [ -z "$PID" ]; do
    echo -n "Enter PID to checkpoint or Control-C to exit: "
    read PID
    
    if [ -n "$(echo $PID |egrep '[^0-9]')" ]; then
	PID=""
    fi
done

echo "Checkpointing PID $PID"
cr_checkpoint -p $PID

if [ $? = 0 ]; then
   echo "Checkpoint file: context.$PID"
else
   echo "cr_checkpoint failed"
fi

