reduced-foam-extend-coheren.../bin/foamProcessInfo

118 lines
3.2 KiB
Text
Raw Permalink Normal View History

2023-09-21 15:05:56 +00:00
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | foam-extend: Open Source CFD
# \\ / O peration | Version: 4.1
# \\ / A nd | Web: http://www.foam-extend.org
# \\/ M anipulation | For copyright notice see file Copyright
#------------------------------------------------------------------------------
# License
# This file is part of foam-extend.
#
# foam-extend 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.
#
# foam-extend 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 foam-extend. 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
#------------------------------------------------------------------------------