Демон?
Не вопрос.Вот пример из проекта, который я пишу
---------------------------
nata.cpp
...
JNIEXPORT jboolean JNICALL Java_nata__1fork
(JNIEnv *, jobject){
jboolean result;
pid_t parpid;
if((parpid=fork())<0)
{
printf("\ncan't fork");
exit(1);
}
else if (parpid!=0)
exit(0);
setsid();
printf ("%d",getpid());
result=true;
return result;
}
...
----------------------------------
nata.java
public native boolean _fork();
public nata()
{
try
{
System.loadLibrary("nata");
}catch (Exception e)
{
System.err.println ("ERROR:\nNo such library \"libnata.so\".\nCheck your library path.");
}
}
...
public boolean fork ()
{
boolean res = false;
try
{
res = _fork ();
}catch (Exception e)
{
System.err.println ("ERROR:\nin library libnata.so: no such instruction \"_fork ()\"\ntry open nata.cpp and edit this void");
res=false;
}
return res;
}
----------------------------------------------
Пример собственно демона:
Server.java
import java.rmi.Naming;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
public class Server
{
public final String SERVER_NAME = "NATA SERVER v0.1";
public static void main (String[] args) throws Exception
{
new nata().fork(); //Тут и создается демон
CS server = new CS(args[0]);
server.runServer();
}
}
-------------------