/* $ dcc exec.c $ a.out good-bye cruel world $ */ #include #include extern char **environ; // simple example of program replacing itself with exec int main(void) { // What is we remove newline (compile with gcc) printf("Hello\n"); // What happens if we do not put /usr/bin/echo in here? char *echo_argv[] = {"/usr/bin/echo","good-bye","cruel","world",NULL}; //What if we just have "echo" execve("/usr/bin/echo", echo_argv, environ); printf("goodbye\n"); // if we get here there has been an error perror("execve"); return 1; }