forking a new process

Hi
I'm currently working with C on UNIX (HPUX) and need to be able to fork a seperate Java process from within a running C process.
I can run the following code from the command line via a script but am having difficulty getting it to work from within the code.
I am trying to use execl. Is execl the correct command to be using?
Any help would be appreciated.
Thanks.

$JAVAHOME/jre/bin/java -cp \

/opt/mv36/em/SMD/data/jct_005/SMD_LCT.jar:/opt/mv36/em/SMD/data/jct_005/jh.jar:/nms/JamToolsTest/jct/MV36CoreProxyNOP.1.1.jar
\
com.marcx.lct.sma11d.sma11d_lct_applet \
-mv36 1 -host 19.3.11.13 -port 20020 \
-inifile /opt/mv36/em/SMD/data/jct_005/ -lang 1 -laf 0 \
-msgset 5 -emaccess 3 -command 221

Well, you can use execl, but in that case, you cannot use the $JAVAHOME env variable. You need to get the value from the env using something like getenv() and create the complete path.

The fork-exec part of the code can look like this (assuming that the path to the java command is /usr/jre/bin):

pid=fork();
if(pid==-1) {
   perror("error in fork!");
}
if(!pid) { /*child process - execute the java command*/
   execl("/usr/jre/bin/java","java","-cp","/opt/mv36/em/SMD/data/jct_005/SMD_LCT.jar:/opt/mv36/em/SMD/data/jct_005/jh.jar:/nms/JamToolsTest/jct/MV36CoreProxyNOP.1.1.jar","com.marcx.lct.sma11d.sma11d_lct_applet","-mv36","1","-host","19.3.11.13","-port","20020","-inifile","/opt/mv36/em/SMD/data/jct_005/","-lang","1","-laf","0","-msgset","5","-emaccess","3","-command","221",(char*)0)
}
else { /*in parent process - wait for child to exit*/
   wait();
}

Cheers.
Though could you tell me whether the current environment should be passed to the process run by the execl?
The execl is succesfull but the underlying java program doesn't start which is I think because it doesn't receive the DISPLAY variable from the calling code. Is there a way to set this for the child process?

Thanks.

Check the man page for fork(2).

It says that the environment does get passed from parent to child. Are you sure that the DISPLAY variable is set in the parent process? Again use getenv to verify that the parent process does indeed have the DISPLAY variable set. If getenv returns NULL, DISPLAY is not set.

Cheers

Thanks for all the help Blowtorch.