Timothy Wall wrote:
On Aug 24, 2007, at 8:33 PM, Jagadeeswaran Rajendiran wrote:
-- Relevant Code --
//linux is the libc.INSTANCE
if((childPid = linux.fork()) == 0){
try{
System.out.println(Thread.currentThread().getName() + " - execing
right now");
Thread.currentThread().setName("New_Execed Thread");
System.out.println(Thread.currentThread().getName() + " - just before
exec");
System.out.println("return value" +
linux.execv("/bin/sleep", testArray));
Try using execl instead. JNA will be treating testArray as a vararg
array, which means it is translating the above into:
linux.execv("/bin/sleep", testArray[0], testArray[1], ..., null);
If you use execl(), that will actually do the right thing.
}catch(Exception e){
System.out.println("exception in abs");
e.printStackTrace();
}
You want to add:
finally {
System.exit(1);
}
If the exec _does_ fail for some reason, or an exception gets thrown,
then you want the new VM (created by fork()) to exit - otherwise you
will have two VMs running with the same set of open files, shared
memory, etc. That would be A Very Bad Thing.