1 #include <fcntl.h> // open
2 #include <stdio.h> // perror
3 #include <unistd.h> // getopt
4 #include <stdlib.h> // exit
6 int main(int argc
, char **argv
, char** envp
)
8 char *exe
= "./hello_world";
12 while ((opt
= getopt(argc
, argv
, "erst")) != -1)
20 open_flags
|= O_RDONLY
;
29 fprintf(stderr
, "bad usage, options are\n"
38 int fd
= open(exe
, open_flags
);
41 perror("open failed:");
48 if (-1 == fexecve(fd
, new_argv
, envp
))
50 perror("fexecv failed:");