Index: /main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java	(revision 31700)
+++ /main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java	(revision 31701)
@@ -751,7 +751,9 @@
 }
 
+// Kill signals, their names and numerical equivalents: http://www.faqs.org/qa/qa-831.html
 // https://stackoverflow.com/questions/8533377/why-child-process-still-alive-after-parent-process-was-killed-in-linux
 // Didn't work for when build scripts run from GLI: kill -TERM -pid
 // but the other suggestion did work: pkill -TERM -P pid did work
+// More reading:
 // https://unix.stackexchange.com/questions/117227/why-pidof-and-pgrep-are-behaving-differently
 // https://unix.stackexchange.com/questions/67635/elegantly-get-list-of-children-processes
@@ -760,24 +762,18 @@
 
 /**
- * On Unix, will kill the process denoted by processID and any subprocessed this launched. Tested on a Mac.
- * @force if true will send the -KILL (-9) signal, which may result in abrupt termination
- * if false, will send the -TERM (-15) signal, which will allow cleanup before termination
- * @killEntireTree if false, will terminate only the process denoted by processID, otherwise all descendants too.
- * @return true if running the kill process returned an exit value of 0
- * 
+ * On Unix, will kill the process denoted by processID and any subprocessed this launched. Tested on a Mac, where this is used.
+ * @param force if true will send the -KILL (-9) signal, which may result in abrupt termination without cleanup
+ * if false, will send the -TERM (-15) signal, which will allow cleanup before termination. Sending a SIGTERM is preferred.
+ * @param killEntireTree if false, will terminate only the process denoted by processID, otherwise all descendants/subprocesses too.
+ * @return true if running the kill process returned an exit value of 0 
 */
-static boolean killUnixProcessTreeWithID(long processID, boolean force, boolean killEntireTree) {
-    // Kill signals, their names and numerical equivalents: http://www.faqs.org/qa/qa-831.html
-
-    /*
-    String cmd = force ? "kill -KILL" : "kill -TERM"; // kill -15 vs kill -9
-    // https://stackoverflow.com/questions/8533377/why-child-process-still-alive-after-parent-process-was-killed-in-linux
-    cmd += killEntireTree ? " -" : " "; // prefix hyphen to pid to kill all subprocesses launched by pid
-    cmd = cmd + processID;
-    */
-
-    String cmd = "pkill -TERM -P " + processID;
-    if(force) {
-	cmd = "pkill -KILL -P " + processID;
+static boolean killUnixProcessWithID(long processID, boolean force, boolean killEntireTree) {
+    
+    String signal = force ? "KILL" : "TERM"; // kill -KILL (kill -9) vs preferred kill -TERM (kill -15)
+    String cmd;
+    if(killEntireTree) { // kill the process denoted by processID and any subprocesses this launched
+	cmd = "pkill -"+signal + " -P " + processID; // e.g. "pkill -TERM -P pid"
+    } else { // kill only the process represented by the processID.
+	cmd = "kill -"+signal + " " + processID; // e.g. "kill -TERM pid"
     } 
 
@@ -800,37 +796,9 @@
 }
 
-/** UNUSED. Kills only the process represented by the processID.
- * @force if true will send the -KILL (-9) signal, which may result in abrupt termination
- * if false, will send the -TERM (-15) signal, which will allow cleanup before termination
- * @return true if running the kill process returned an exit value of 0
-*/
-static boolean killUnixProcessWithID(long processID, boolean force) {
-    // Kill signals, their names and numerical equivalents: http://www.faqs.org/qa/qa-831.html
-    String cmd = force ? "kill -KILL" : "kill -TERM"; // kill -15 vs kill -9
-    cmd = cmd + " " + processID;
-
-    SafeProcess proc = new SafeProcess(cmd);
-    int exitValue = proc.runProcess();
-    if(exitValue != 0) {
-	log("@@@ Not able to successfull terminate process, got exitvalue " + exitValue);
-	log("@@@ Got output " + proc.getStdOutput()); 
-	log("@@@ Got err output " + proc.getStdError());
-	// caller can try again with kill -KILL, by setting force parameter to true
-	return false;
-    } else {
-	if(force) {
-	    log("@@@ Successfully sent SIGKILL to unix process " + processID);
-	} else { 
-	    log("@@@ Successfully sent SIGTERM to unix process " + processID);
-	}
-	return true;
-    }    
-}
-
 
 // On linux and mac, p.destroy() suffices to kill processes launched by p as well.
 // On Windows we need to do more work, since otherwise processes launched by p remain around executing until they naturally terminate.
 // e.g. full-import.pl may be terminated with p.destroy(), but it launches import.pl which is left running until it naturally terminates.
-static void destroyProcess(Process p) {
+public static void destroyProcess(Process p) {
     log("### in SafeProcess.destroyProcess(Process p)");
 
@@ -855,6 +823,6 @@
 	    boolean forceKill = false;
 	    boolean killEntireProcessTree = true;
-	    if(!killUnixProcessTreeWithID(pid, !forceKill, killEntireProcessTree)) { // send sig TERM (kill -15 or kill -TERM)
-		killUnixProcessTreeWithID(pid, forceKill, killEntireProcessTree); // send sig KILL (kill -9 or kill -KILL)
+	    if(!killUnixProcessWithID(pid, !forceKill, killEntireProcessTree)) { // send sig TERM (kill -15 or kill -TERM)
+		killUnixProcessWithID(pid, forceKill, killEntireProcessTree); // send sig KILL (kill -9 or kill -KILL)
 	    }
 	}
@@ -888,5 +856,5 @@
 
 
-// UNUSED
+// UNUSED and INCOMPLETE
 // But if this method is needed, then need to parse childpids printed by "pgrep -P pid" and write recursive step
 // The childpids are probably listed one per line, see https://unix.stackexchange.com/questions/117227/why-pidof-and-pgrep-are-behaving-differently
@@ -904,7 +872,10 @@
 	p.destroy();
     } else {
-	// get rid of process with current pid
-	if(!SafeProcess.killUnixProcessWithID(parent_pid, false)) { // send kill -TERM, kill -15
-	    SafeProcess.killUnixProcessWithID(parent_pid, true); // send kill -9, kill -KILL
+	boolean forceKill = true;
+	boolean killSubprocesses = true;
+	// get rid of process denoted by the current pid (but not killing subprocesses it may have launched,
+	// since we'll deal with them recursively)
+	if(!SafeProcess.killUnixProcessWithID(parent_pid, !forceKill, !killSubprocesses)) { // send kill -TERM, kill -15
+	    SafeProcess.killUnixProcessWithID(parent_pid, forceKill, !killSubprocesses); // send kill -9, kill -KILL
 	}
     }
