#!/bin/sh -T
kill_all()
{
echo 'killing everything'
kill $SPID $CPID 2 /dev/null
exit 0
}
trap kill_all SIGCHLD
./child
CPID=$!
sleep 5
SPID=$!
echo child is $CPID
echo sleeper is $SPID
wait
This is very nice. However I'm getting one problem still. My
I decided that I want the exec line at the end of the script because I
want the exit code of the script to be the exit code of the Java
process. I'm willing to live with the fact that the sleep thread will
wait its full 3 seconds. So my final script is this:
#!/bin/sh
cd `dirname $0`
This is a shell scripting question, it is not specific to FreeBSD.
I am writing a script that I want to terminate after 1 second (because
it has the potential to infinite loop). The script I have so far is:
#!/bin/sh
cd `dirname $0`
CLASSPATH=mapgen.jar
export CLASSPATH
/usr/local/bin/java
The java process has the potential to run forever, and I want it to
run for at most 1 second then get killed. I could write a parent
script that somehow gets the PID of the child script, but the problem
is that the java program writes to standard out, the result of the
program is written to
On Thu, 22 Jan 2009 12:41:14 -0800
Nerius Landys nlan...@gmail.com wrote:
/usr/local/bin/java PipeGenerator $*
sleep 1
kill the java command if not already killed
Also with the above code I would be waiting for 1 second even if the
java process finished sooner. But that is a penalty I'm
On Thu, Jan 22, 2009 at 3:41 PM, Nerius Landys nlan...@gmail.com wrote:
This is a shell scripting question, it is not specific to FreeBSD.
I am writing a script that I want to terminate after 1 second (because
it has the potential to infinite loop). The script I have so far is:
#!/bin/sh
#!/bin/sh
java()
{
echo 'start'
sleep 5
echo 'stop'
}
sleep 1 kill $$
java
kill $!
{
echo 'start'
sleep 5
echo 'stop'
}
sleep 1 kill $$
java
kill $!
That is very genious. However, I had to add an exec to the parent
script. Here
Actually, because of the exec in the parent script, the line below
it, the killing terminator process line, never gets reached. So the
terminator process that waits to kill its parent always waits the full
5 seconds in the background. If I pipe the output of the parent
script through less, it
On Thu, Jan 22, 2009 at 5:58 PM, Nerius Landys nlan...@gmail.com wrote:
Actually, because of the exec in the parent script, the line below
it, the killing terminator process line, never gets reached. So the
terminator process that waits to kill its parent always waits the full
5 seconds in