Is it possible to kill a java program's execution from terminal automatically after specific amount of time (when running not compiling). For example, I like to stop the following after 10 seconds:
java examples.Example
Is it possible to kill a java program's execution from terminal automatically after specific amount of time (when running not compiling). For example, I like to stop the following after 10 seconds:
java examples.Example
If you don't need to watch the output of the process:
#!/bin/bash
{
java examples.Example >/some/place.log &
echo $!
wait $!
} | {
sleep 10
kill $(read PID; echo $PID)
}
This script will launch your process in a subshell, transmit its PID to the waiting subshell, which will wait for 10 seconds and kill it.
If you know that your process will always take longer than 10 seconds, you can simply do this:
java examples.Example >/some/place.log &
sleep 10
kill $!