Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2007, 11:00 PM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 154
Rep Power: 3 programmingnoob is on a distinguished road
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?
programmingnoob is offline   Reply With Quote
Old Feb 2nd, 2007, 12:46 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
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>
Jimbo is offline   Reply With Quote
Old Feb 2nd, 2007, 8:07 AM   #3
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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
Game_Ender is offline   Reply With Quote
Old Feb 6th, 2007, 3:08 PM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
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.
jim mcnamara is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC