日期:2014-05-16  浏览次数:20533 次

Linux exec方法族简单用法


MAN (Manual pager utils) :
       execl, execlp, execle, execv, execvp ,execve- execute a file

       #include <unistd.h>

       extern char **environ;

       int execl(const char *path, const char *arg, ...);


       int execlp(const char *file, const char *arg, ...);


       int execle(const char *path, const char *arg, ..., char * const envp[]);

       int execv(const char *path, char *const argv[]);


       int execvp(const char *file, char *const argv[]);

      int execve(const char *filename, char *const argv[], char *const envp[]);



execl("/bin/ls", "-al", (char*)0);

-------------------------------------------------

   char *envp[] = {"-al", "."};
   execle("/bin/ls","ls",  NULL, envp);

------------------------------------------------ 
execlp("ls", "ls", "-l", ".", NULL );

----------------------------------------- 


char*evnp[] = {"ls", "-al", NULL};
execvp("ls", evnp);
--------------------------------------

char*envp[] = {"ls","-l", ".",NULL};
 execv("/bin/ls",  envp);
--------------------------------------

char*argv[] ={"ls", "-l",".", NULL};
char*envp[] ={ NULL};
execve("/bin/ls", argv, envp);