From c44985fb8db5e76c5822be2db5995c98ac5c816f Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Fri, 1 Feb 2008 22:40:02 +0100 Subject: [PATCH] test.sh: prepared process checks --- test.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test.sh b/test.sh index b94da93..3ccb45b 100755 --- a/test.sh +++ b/test.sh @@ -1525,6 +1525,47 @@ testoptions () { return 0 } +# check if a process with given pid exists; print its ps line +# if yes: prints line to stdout, returns 0 +# if not: prints ev.message to stderr, returns 1 +ifprocess () { + local l + case "$UNAME" in + Linux) l="$(ps -fade |grep "^.........$(printf %5u $1)")" ;; + esac + if [ -z "$l" ]; then + return 1; + fi + echo "$l" + return 0 +} + +# check if the given pid exists and has child processes +# if yes: prints child process lines to stdout, returns 0 +# if not: prints ev.message to stderr, returns 1 +childprocess () { + local l + case "$UNAME" in + Linux) l="$(ps -fade |grep "^...............$(printf %5u $1)")" ;; + esac + if [ -z "$l" ]; then + return 1; + fi + echo "$l" + return 0 +} + +# check if the given process line refers to a defunct (zombie) process +# yes: returns 0 +# no: returns 1 +isdefunct () { + local l + case "$UNAME" in + Linux) l="$(echo "$1" |grep ' $')" ;; + esac + [ -n "$l" ]; +} + unset HAVENOT_IP4 # check if an IP4 loopback interface exists runsip4 () { @@ -7739,6 +7780,7 @@ $CMD1 2>"${te}1" >"$tf" & pid=$! # background process id waittcp4port $PORT (echo "$da"; sleep 2) |$CMD2 2>"${te}2" +kill "$pid" 2>/dev/null; wait if ! echo "$da" |diff - "$tf" >"$tdiff"; then $PRINTF "$FAILED: $SOCAT:\n" echo "$CMD1"