Merge commit 'b5be6201e00421a59e574a07b3d28cde5defff84'
[foam-extend-4.0.git] / bin / foamProcessInfo
blobcbaf078f8bf54c6dd64e7ff6cddd866ec22b46b1
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 4.0
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation, either version 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamProcessInfo
28 # Description
29 # Collects user's process status information into file. File contains one
30 # line per process:
32 # pid state command
34 # state is one of 'RUNN' 'SUSP' 'OTHR',
35 # command is the argv[0]
37 # Tested on Linux,IRIX,SunOS
39 #------------------------------------------------------------------------------
41 PROGNAME=`basename $0`
42 TMPFILE=/tmp/${PROGNAME}$$.tmp
43 AWKFILE=/tmp/${PROGNAME}$$.awk
45 if [ `uname -s` = Linux ]
46 then
47 ECHO='echo -e'
48 else
49 ECHO='echo'
53 if [ $# -ne 1 ]
54 then
55 echo "Error : $PROGNAME : insufficient arguments" 1>&2
56 exit 1
60 outputFile=$1
61 rm -f $outputFile
64 ARCH=`uname`
66 #-- Force standards behaving ps
67 # Get info on all $USER processes
68 case $ARCH in
69 HP-UX*)
70 UNIX95=a; export UNIX95
72 IRIX*)
73 _XPG=1; export _XPG
75 esac
77 case $ARCH in
78 SunOS*)
79 ps -e -o 'pid,f,s,comm' > $TMPFILE
81 HP-UX*)
82 ps -e -o 'pid,flags,state,comm' > $TMPFILE
85 ps -e -o 'pid,flag,state,comm' > $TMPFILE
86 esac
89 rm -f $AWKFILE; touch $AWKFILE
90 case $ARCH in
91 IRIX*)
92 echo '($2 == 40) || ($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
93 echo '($3 == "R") || ($3 == "S") || ($3 == "D") {print $1 " RUNN // " $4; next}' >> $AWKFILE
94 echo '{print $1 " OTHR // " $4}' >> $AWKFILE
96 Linux*)
97 echo '($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
98 echo '($3 == "R") || ($3 == "S") || ($3 == "D") {print $1 " RUNN // " $4; next}' >> $AWKFILE
99 echo '{print $1 " OTHR // " $4}' >> $AWKFILE
101 SunOS*)
102 echo '($3 == "T") {print $1 " SUSP // " $4; next}' >> $AWKFILE
103 echo '($3 == "O") || ($3 == "S") || ($3 == "R") {print $1 " RUNN // " $4; next}' >> $AWKFILE
104 echo '{print $1 " OTHR // " $4}' >> $AWKFILE
107 echo "Error : $PROGNAME : unsupported achitecture $ARCH"
109 esac
111 $ECHO "(" > $outputFile
112 tail +2 $TMPFILE | awk -f $AWKFILE >> $outputFile
113 $ECHO ")" >> $outputFile
115 rm -f $TMPFILE $AWKFILE
117 #------------------------------------------------------------------------------