#! /bin/bash


# default libexecdir used to bootstrap scripts
libexecdir=${GLOBUS_LOCATION}/libexec

# load GRIS CPU common code and initialization
. ${libexecdir}/grid-info-mem-common

#########################################################################

probe_resource_mem ()
{
    ${GLOBUS_SH_TOP-top} -d1 -b 2> /dev/null | \
    {
	read loadavgs
	read processes
	read blank
	IFS=":,"
	read Memory memtot memfree swapuse swapfree
	IFS="$IFS_save"

	cat > /dev/null


        _mem_size_mbytes=`drop_MKG $memtot`
        _mem_free_mbytes=`drop_MKG $memfree`

        _vm_free_mbytes=`drop_MKG $swapfree`
        _vm_size_mbytes=`drop_MKG $swapuse`
        _vm_size_mbytes=`$EXPR ${_vm_free_mbytes} + ${_vm_size_mbytes}`

	# run this in initialized subshell environment
	emit_resource_mem_descriptions
    }
}

#############
# do the work
probe_resource_mem
