[Very OT] C snippet issue
- Posted by mistertrik at hotmail.com May 01, 2003
- 528 views
Again, apologies... this is not a C discussion board. For some reason... this code never returns! chargv is a pointer to a pointer to a char... an array of strings. Built for a POSIX environment. void runextcommand(char **chargv) { int child_pid; if ((child_pid = fork()) == 0) /*Here the program splits into 2. If this is the child process, then...**/ { if (execvp(chargv[0], chargv) == -1) perror ("Invalid command"); /*Tell the user there was something wrong, and why.*/ exit (1); /*If the child process is still active, it doesn't need to be, so quit it.*/ printf("Debug: child\n"); } else /*If this is the parent process...*/ { printf("Debug: parent\n"); wait (NULL); /*Wait until the child dies, or the parent process is given an interrupt of somekind*/ /*At this stage, the stdin and stdout file handles may have been rerouted. Set them back to normal*/ freopen("/dev/stdout", "w", stdout); freopen("/dev/stderr", "w", stderr); freopen("/dev/stdin", "r", stdin); return; } } ===================================================== .______<-------------------\__ / _____<--------------------__|=== ||_ <-------------------/ \__| Mr Trick