Annotation of ircnowd/src/testsuite/getpid.sh, Revision 1.1.1.1
1.1 tomglok 1: #!/bin/sh
2: # ngIRCd Test Suite
3:
4: # did we get a name?
5: [ $# -ne 1 ] && exit 1
6:
7: [ -x /bin/pidof ] && exec /bin/pidof -s $@
8:
9: # detect flags for "ps" and "head"
10: UNAME=`uname`
11: if [ $UNAME = "FreeBSD" ]; then
12: PS_FLAGS="-a"; PS_PIDCOL="1"; HEAD_FLAGS="-n 1"
13: elif [ $UNAME = "A/UX" ]; then
14: PS_FLAGS="-af"; PS_PIDCOL="2"; HEAD_FLAGS="-1"
15: elif [ $UNAME = "GNU" ]; then
16: PS_FLAGS="-ax"; PS_PIDCOL="2"; HEAD_FLAGS="-n 1"
17: elif [ $UNAME = "Haiku" ]; then
18: PS_FLAGS="-o Id -o Team"; PS_PIDCOL="1"; HEAD_FLAGS="-1"
19: elif [ $UNAME = "Linux" ]; then
20: PS_FLAGS="ax"; PS_PIDCOL="1"; HEAD_FLAGS="-n 1"
21: elif [ $UNAME = "SunOS" ]; then
22: PS_FLAGS="-af"; PS_PIDCOL=2; HEAD_FLAGS="-n 1"
23: else
24: PS_FLAGS="-af"; PS_PIDCOL="2"; HEAD_FLAGS="-n 1"
25: ps $PS_FLAGS > /dev/null 2>&1
26: if [ $? -ne 0 ]; then PS_FLAGS="a"; PS_PIDCOL="1"; fi
27: fi
28:
29: # debug output
30: #echo "$0: UNAME=$UNAME"
31: #echo "$0: PS_FLAGS=$PS_FLAGS"
32: #echo "$0: PS_PIDCOL=$PS_PIDCOL"
33: #echo "$0: HEAD_FLAGS=$HEAD_FLAGS"
34:
35: # search PID
36: ps $PS_FLAGS > procs.tmp
37: cat procs.tmp | \
38: grep -v "$0" | grep "$1" | \
39: awk "{print \$$PS_PIDCOL}" | \
40: sort -n > pids.tmp
41: pid=`head $HEAD_FLAGS pids.tmp`
42: rm -rf procs.tmp pids.tmp
43:
44: # validate PID
45: [ "$pid" -gt 1 ] > /dev/null 2>&1
46: [ $? -ne 0 ] && exit 1
47:
48: echo $pid
49: exit 0
50:
51: # -eof-
CVSweb