The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Forking with Tclsh vs Wish pghamami Shell Programming and Scripting 3 05-06-2008 12:33 PM
Testing the forking process. Vitamin254 UNIX for Dummies Questions & Answers 0 02-22-2008 07:12 PM
VERY confused about forking of child process JamesByars UNIX for Advanced & Expert Users 7 02-22-2008 12:31 PM
forking process. kymthasneem High Level Programming 2 06-23-2007 10:00 AM
Forking manjuWicky UNIX for Advanced & Expert Users 3 10-07-2005 12:01 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2006
Registered User
 

Join Date: Jun 2006
Posts: 6
Stumble this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-18-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
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):
Code:
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();
}
Reply With Quote
  #3 (permalink)  
Old 06-19-2006
Registered User
 

Join Date: Jun 2006
Posts: 6
Stumble this Post!
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.
Reply With Quote
  #4 (permalink)  
Old 06-19-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
Check the man page for fork(2).
Quote:
Originally Posted by man page of fork
The child process inherits the following attributes from the parent
process:

+ Real, effective, and saved user IDs.
+ Real, effective, and saved group IDs.
+ List of supplementary group IDs (see getgroups(2)).
+ Process group ID.
+ Environment.
+ File descriptors.
+ Close-on-exec flags (see exec(2)).
+ Signal handling settings (SIG_DFL, SIG_IGN, address).
+ Signal mask (see sigvector(2)).
+ Profiling on/off status (see profil(2)).
+ Command name in the accounting record (see acct(4)).
+ Nice value (see nice(2)).
+ All attached shared memory segments (see shmop(2)).
+ Current working directory
+ Root directory (see chroot(2)).
+ File mode creation mask (see umask(2)).
+ File size limit (see ulimit(2)).
+ Real-time priority (see rtprio(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
Reply With Quote
  #5 (permalink)  
Old 06-20-2006
Registered User
 

Join Date: Jun 2006
Posts: 6
Stumble this Post!
Thanks for all the help Blowtorch.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0