0

I call the execvp function like so:

 int return_status = execvp("./myprogram", argv + 2);
 printf("return status is %d", return_status);

./myprogram does run, but the printf statement never runs. Why might that be the case?

zengod
  • 1,114
  • 13
  • 26

1 Answers1

1

In your example, if execvp succeeds, your process is now running ./myprogram. It cannot return to the calling code because the calling code has been replaced.

The purpose of the execvp function is to replace the currently-executing code with that of the specified executable. It returns only if it fails. If you want two processes, you need to call fork first and have the child call execvp. You can also use functions like system or popen that do this for you.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278