Skip to content
Snippets Groups Projects
foamProcessInfo 3.11 KiB
Newer Older
Henry's avatar
Henry committed
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
#    \\/     M anipulation  |
#-------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM.
#
#     OpenFOAM is free software: you can redistribute it and/or modify it
#     under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
#     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#     for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
#
# Script
#     foamProcessInfo
#
# Description
#     Collects user's process status information into file. File contains one
#     line per process:
#
#        pid state command
#
#     state is one of 'RUNN' 'SUSP' 'OTHR',
#     command is the argv[0]
#
#     Tested on Linux,IRIX,SunOS
#
#-------------------------------------------------------------------------------

PROGNAME=`basename $0`
TMPFILE=/tmp/${PROGNAME}$$.tmp
AWKFILE=/tmp/${PROGNAME}$$.awk

if [ `uname -s` = Linux ]
then
    ECHO='echo -e'
else
    ECHO='echo'
fi


if [ $# -ne 1 ]
then
    echo "Error : $PROGNAME : insufficient arguments" 1>&2
    exit 1
fi


outputFile=$1
rm -f $outputFile


ARCH=`uname`

#-- Force standards behaving ps
#   Get info on all $USER processes
case $ARCH in
  HP-UX*)
    UNIX95=a; export UNIX95
    ;;
  IRIX*)
    _XPG=1; export _XPG
    ;;
esac

case $ARCH in
  SunOS*)
    ps -e -o 'pid,f,s,comm' > $TMPFILE
    ;;
  HP-UX*)
    ps -e -o 'pid,flags,state,comm' > $TMPFILE
    ;;
  *)
    ps -e -o 'pid,flag,state,comm' > $TMPFILE
esac


rm -f $AWKFILE; touch $AWKFILE
case $ARCH in
  IRIX*)
    echo '($2 == 40) || ($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
    echo '($3 == "R") || ($3 == "S") || ($3 == "D") {print $1 " RUNN // " $4; next}' >> $AWKFILE
    echo '{print $1 " OTHR // " $4}' >> $AWKFILE
    ;;
  Linux*)
    echo '($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
    echo '($3 == "R") || ($3 == "S") || ($3 == "D") {print $1 " RUNN // " $4; next}' >> $AWKFILE
    echo '{print $1 " OTHR // " $4}' >> $AWKFILE
    ;;
  SunOS*)
    echo '($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
    echo '($3 == "O") || ($3 == "S") || ($3 == "R") {print $1 " RUNN // " $4; next}' >> $AWKFILE
    echo '{print $1 " OTHR // " $4}' >> $AWKFILE
    ;;
  *)
    echo "Error : $PROGNAME : unsupported achitecture $ARCH"
    ;;
esac

$ECHO "(" > $outputFile
tail +2 $TMPFILE | awk -f $AWKFILE >> $outputFile
$ECHO ")" >> $outputFile

rm -f $TMPFILE $AWKFILE

#------------------------------------------------------------------------------