The UNIX and Linux Forums  

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



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-07-2008
Ametis1970 Ametis1970 is offline
Registered User
 

Join Date: Mar 2008
Posts: 4
Thank you for answers !

To era:

Maybe I was not clear.
Supposed I want to calculate a product of two integers in child process.
So, child.c looks like that:

... some #include

int main(int argc, char *argv[])
{
int a;
int b;
a=atoi(argv[1]);
b=atoi(argv[2]);
return a*b;
}

Under Windows, if I use this code, in parent.c:

int main()
{
int result;
char *args[4];
// prepare arguments for child process
args[0] = "child.exe";
args[1] = argv[1];
args[2] = argv[2];
args[3] = NULL;
// launch the child process
result=_spawnvp (_P_WAIT, args[0], args);
printf("Product: %d, result);
return 0;
}

I'm able to catch the return product from child (a*b) as return from _spawnvp() function in result variable.
Under Linux, posix_spawnp() or wait() return only EXIT_FAILURE or EXIT_SUCCES. I didn't find a way to catch in the parent the product value calculate in the child (value which is returned in child).

To ramen_noodle:
I don't understand you startChild() function.
I don't know what is funion. Is a function or a data type ? I didn't find reference to funion().
Reply With Quote