Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: The Halting Problem

On Dec 28, 10:49am, Chris Johnson wrote:
} I tried backgrounding the long-running job, capturing its PID, and
} passing that to sleepkill as the process to kill:
}   java Foo &
}   longpid=$!
}   sleepkill $longpid &
}   sleeppid=$!
}   wait $longpid
}   # Kill the sleep timer, if necessary.
}   kill $sleeppid 2>/dev/null
} This kills the long-running job on timeout, but it also puts the job
} in the background. Control-C won't kill it.

You're almost there.  If ctrl+c won't kill the java process in the above
example, then there's some additional signal handling going on behind
the scenes, and you just need to add a trap before the "wait":

   TRAPINT() { kill $longpid }

So that when wait is interrupted you send off a signal to java.  You
probably also want to kill $sleeppid there, but because it's a shell
function it may ignore the default TERM signal, so:

   TRAPINT() {
     kill $longpid
     kill -HUP -$$

That should clean everything up.

Messages sorted by: Reverse Date, Date, Thread, Author