![]() |
child process - chdir and execXX
so there is a child process...
and the child process "changes its directory (chdir() call), changes its address space (execXX() call) to execute the “ls” command, and exits." the thing is I wanted to use execlp() to execute the "ls" command, but when the call execlp () succeeds, it never returns. so how do i make sure the child process does exit? |
When you call exec, you're pretty much changing the program running in that process. Whatever is being exec'ed, once that's done it'll quit as though it had been executed from the start. So the `ls` will quit when it's done and the process will terminate.
Unless the child hangs, it'll terminate; however, since it's a separate process, keeping tabs on it isn't exactly neat. You could have the parent wait(), but if the child hangs that'll just keep the parent waiting as well. I don't know if you can check the status of a process arbitrarily, but there are some macros (at least in Linux) for getting some information on a process you've waited on (and which has terminated). |
You can also do a no-blocking wait on a child process to see if it has stopped. Just check the GNU C library manual. It describes all the needed functions in detail.
|
Have the child process call sleep(9999);
But why do you want that? If this is related your your other post, then I'd guess you're playing around with code, which is a good way to learn. But, in the real world, unless you are building a daemon, you are wasting system resources by having a process park itself in memory for no reason. |
| All times are GMT -5. The time now is 2:01 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC