![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getting the return code of forked child process (ftp) | KittyJ | High Level Programming | 7 | 08-19-2007 12:44 AM |
| display in a child process a command called in the parent one | remid1985 | High Level Programming | 7 | 01-19-2007 02:40 PM |
| how to find the chid process id from given parent process id | guhas | Shell Programming and Scripting | 3 | 10-13-2005 05:13 AM |
| Implementing 2 pipes between a parent and child process | bwgoudey | High Level Programming | 2 | 09-24-2005 08:14 PM |
| parent and child process question? | tosa | High Level Programming | 0 | 02-16-2005 11:04 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Can a child process return a specific value to a parent process ?
Hello everybody !
I have two C source file: child.c and parent.c. child.c looks like that: Code:
int main()
{
How can I get in parent the return code from child (here value is 15647) without using interprocess communication (pipe, shared memory, ...) ? Is there any way to do that without IPC ? Thank you ! |
| Forum Sponsor | ||
|
|
|
|||
|
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(). |
|
|||
|
You do get slightly more with WEXITSTATUS(status) after you've done a waitpid(pid, &status, ...) but this was never meant as a facility for anything more than very small integers.
I I understand ramen_noodle's hint correctly, you would have a function pointer "funion" which you run in the child, and which returns its result in the memory location pointed to by anarg. What are you trying to achieve; why is regular IPC out of the question? |
|||
| Google UNIX.COM |