after executing execvp()... program hangs up

Hi ,

I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up :mad:

Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up

values of variables before execution of this code

intial_command=more
argList[0]=more
argList[1]=NULL

child code:    

{
close(0);
dup2(pipes[0][1],0);
close(pipes[0][0]);
execvp(intial_command,argList);
}
parent code:
printf("after child");
waitpid(pid,&status,0);

i guess since i have closed the stdin using close(0) thats y i m not able to input anythng even after execvp()...but as far my knowledge once the execvp() functions gets executed the child process gets terminated..so my program should resume to parent process

close(0);
dup2(pipes[0][1],0);
close(pipes[0][0]);open(0);
execvp(intial_command,argList);

Isn't that open(0) giving you any errors during compilation? The open syscall needs atleast two arguments.

BTW it wasnt giving any system error...dunno kno how :rolleyes:

execvp does not create a new process. It replaces the current process.

Proper sequence of events would be:

  • fork() to copy current process. The new process will be identical to the old one with one differnce -- the child and parent get different return values from fork().
  • Close and/or rearrange file descriptors as you please in the child code to make whatever the stdin/stdout/stderr/etc.
  • Call execvp in the child process

Maybye you're using fork already, but that code snippet doesn't show it..