6 messages in net.java.dev.jna.usersRe: [jna-users] Re: JNA (fork and exec)
FromSent OnAttachments
Timothy WallAug 27, 2007 12:59 pm 
Wayne MeissnerAug 27, 2007 5:28 pm 
Jagadeeswaran RajendiranAug 28, 2007 4:56 pm 
Timothy WallAug 28, 2007 6:51 pm 
Jagadeeswaran RajendiranAug 29, 2007 5:49 pm 
Timothy WallAug 29, 2007 8:48 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Re: JNA (fork and exec)Actions...
From:Wayne Meissner (wmei@gmail.com)
Date:Aug 27, 2007 5:28:04 pm
List:net.java.dev.jna.users

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.