Newer
Older
#!/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'
ECHO='echo'
if [ $# -ne 1 ]
then
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
#------------------------------------------------------------------------------