The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-03-2009
p00ndawg p00ndawg is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 8
Why does my child process not exit?

Im sure it has something to do with the wait() call, but everything ive tried either leaves me with a zombie or with the exec executing indefinitely.

Code:
switch(pid = fork())
{
case -1:perror("fork failed");
exit(1);

case 0: 
if(key == "cd")
    {
        
        execl("/bin/cd", "cd", data, (char *)0);
                
    }
    else{
        execl("/bin/sh", key, data, (char *)0);
        perror("exec failed");
        exit(status);    
        }
        
            
default:     waitpid (pid, &status, 0); 
             printf("Done: \n");
        exit(0);
         
}


Last edited by vbe; 07-03-2009 at 09:51 AM.. Reason: added code tag