1 #!/bin/bash 2 # 3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 # 6 # This code is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 only, as 8 # published by the Free Software Foundation. 9 # 10 # This code is distributed in the hope that it will be useful, but WITHOUT 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 # version 2 for more details (a copy is included in the LICENSE file that 14 # accompanied this code). 15 # 16 # You should have received a copy of the GNU General Public License version 17 # 2 along with this work; if not, write to the Free Software Foundation, 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 # 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 # or visit www.oracle.com if you need additional information or have any 22 # questions. 23 # 24 25 # @test 26 # @bug 4244896 27 # @summary Adding several methods to the Process class. 28 # isAlive(): check to see if a process has not exited 29 # destroyForcibly: implementation dependent force process destroy. 30 # (e.g. send the process a SIGKILL on Linux/Solaris/Mac) 31 # waitFor(timeout): add a timeout param to waitFor() 32 # @run shell ProcessKillTest.sh 33 34 if [ "${TESTSRC}" = "" ] 35 then TESTSRC=. 36 fi 37 38 if [ "${TESTJAVA}" = "" ] 39 then 40 PARENT=`dirname \`which java\`` 41 TESTJAVA=`dirname ${PARENT}` 42 echo "TESTJAVA not set, selecting " ${TESTJAVA} 43 echo "If this is incorrect, try setting the variable manually." 44 fi 45 46 BIT_FLAG="" 47 48 # set platform-dependent variables 49 OS=`uname -s` 50 case "$OS" in 51 Darwin ) 52 NULL=/dev/null 53 PS=":" 54 FS="/" 55 CHMOD="${FS}bin${FS}chmod" 56 ;; 57 SunOS | Linux ) 58 NULL=/dev/null 59 PS=":" 60 FS="/" 61 CHMOD="${FS}bin${FS}chmod" 62 ## for solaris, linux it's HOME 63 FILE_LOCATION=$HOME 64 if [ -f ${FILE_LOCATION}${FS}JDK64BIT -a ${OS} = "SunOS" ] 65 then 66 BIT_FLAG=`cat ${FILE_LOCATION}${FS}JDK64BIT` 67 fi 68 ;; 69 Windows* | CYGWIN* ) 70 NULL=NUL 71 PS=";" 72 FS="\\" 73 CHMOD="chmod" 74 ;; 75 * ) 76 echo "Unrecognized system!" 77 exit 1; 78 ;; 79 esac 80 81 THIS_DIR=`pwd` 82 83 TESTSH="#!/bin/bash 84 echo \"ProcessTrap.sh started, trapping SIGTERM/SIGINT\" 85 trap bashtrap SIGTERM SIGINT 86 bashtrap() 87 { 88 echo \"SIGTERM/SIGINT detected!\" 89 } 90 91 while : 92 do 93 sleep 1; 94 done" 95 96 echo "$TESTSH" > ${THIS_DIR}${FS}ProcessTrap.sh 97 ${CHMOD} a+x ${THIS_DIR}${FS}ProcessTrap.sh 98 99 ${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}ProcessKillTest.java 100 101 ${TESTJAVA}${FS}bin${FS}java ${BIT_FLAG} ProcessKillTest > test.out 2>&1 102 103 STATUS=$? 104 105 cat test.out 106 107 exit $STATUS