![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 154
Rep Power: 3
![]() |
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? |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
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).
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|