Hello,
I am trying to spawn a process using the following code.
A new process is forked but hangs in execvp.
A look at the process table shows that a java process is spawned but no
konsole process.
Is this an JNA issue ?
- Ron
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((System.getProperty("os.name").startsWith("Windows")
? "msvcrt" : "c"), CLibrary.class);
int atol(String s);
int fork();
void exit(int status);
/*
* int execv (const char *filename, char *const argv[])
*/
int execvp (String filename, String[] argv);
}
public static void main(String[] args)
{
System.out.println(System.getProperty("os.name"));
int pid = 0;
if ((pid = CLibrary.INSTANCE.fork()) == 0)
{
CLibrary.INSTANCE.execvp("konsole", new String[]{"konsole",
"--noclose"});
CLibrary.INSTANCE.exit(-1);
}
else if (pid > 0)
{
System.out.println("forked "+pid);
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
else if (pid < 0)
System.out.println("could not fork a process");
}