Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Little fork() question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Little fork() question



On Wednesday, February 12, 2003, at 10:12 AM, email@hidden wrote:
The 'ten' program is the main() that is also listed in my program listing, between the /* */ above the other. I've included everything below again.

Oops. It's early. ;-)

'./ten' at itsself runs perfectly at the command line. The 'done' message does not appear, so 'ten' should be running fine. Well, it does pop-up in the Process Viewer, so it runs yes, but only a fraction of a second, but it should wait for ten seconds (see listing below) and then exit. Indeed, I do not want to see the 'done' message, it was only put there as a test.

execvp("./ten",0); // this is the code the child runs

The problem is with the execvp(). You aren't providing an argument list terminated with a NULL element, you are providing an entirely NULL argument list. That's not kosher, and the ./ten application itself is crashing just before main() as a result. You want something like:


char *const exec_args[2] = {"./ten", 0};
execvp(exec_args[0], exec_args);

 --Jim

PS: Given an absolute path like "./ten", you really don't need to go the expense of doing a path-based exec() like execvp() provides. Just use execv(). It's more efficient.
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.




References: 
 >Re: Little fork() question (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.