Chinaunix首页 | 论坛 | 博客
  • 博客访问: 861519
  • 博文数量: 133
  • 博客积分: 7117
  • 博客等级: 少将
  • 技术积分: 1846
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-16 21:30
文章分类

全部博文(133)

文章存档

2012年(1)

2011年(4)

2010年(2)

2009年(57)

2008年(69)

分类: LINUX

2008-10-07 09:56:21

EXEC(3)                                   Linux Programmer's Manual                                  EXEC(3)
 
NAME
       execl, execlp, execle, execv, execvp - execute a file
 
SYNOPSIS
       #include
 
       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[]);
 
DESCRIPTION
       The  exec()  family  of  functions  replaces the current process image with a new process image.  The functions described in this manual page are front-ends for the function execve(2).  (See  the  manual page for execve(2) for detailed information about the replacement of the current process.)
 
       The initial argument for these functions is the pathname of a file which is to be executed.
 
       The  const  char *arg and subsequent ellipses in the execl(), execlp(), and execle() functions can be thought of as arg0, arg1, ..., argn.  Together they describe a list of one or more pointers to  null-terminated  strings  that  represent  the argument list available to the executed program.  The first
argument, by convention, should point to the filename associated with the file being  executed.   The list of arguments must be terminated by a NULL pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL.
 
       The execv() and execvp() functions provide an array of pointers to null-terminated strings that  rep-resent  the  argument  list  available to the new program.  The first argument, by convention, should point to the filename ssociated with the file being executed.  The array of pointers must be  termi-nated by a NULL pointer.
 
       The  execle()  function  also specifies the environment of the executed process by following the NULL pointer that terminates the list of arguments in the parameter list or the pointer to the argv  array with  an  additional parameter.  This additional parameter is an array of pointers to null-terminated strings and must be terminated by a NULL pointer.  The other functions take the environment  for  the new process image from the external variable environ in the current process.
 
   Special semantics for execlp() and execvp() The  functions execlp() and execvp() will duplicate the actions of the shell in searching for an exe-cutable file if the specified filename does not contain a slash (/) character.  The  search  path  is
the  path  specified  in the environment by the PATH variable.  If this variable isn't specified, the default path ":/bin:/usr/bin" is used.  In addition, certain errors are treated specially.
 
       If permission is denied for a file (the attempted execve(2) returned EACCES),  these  functions  will continue searching the rest of the search path.  If no other file is found, however, they will return with the global variable errno set to EACCES.
 
       If the header of a file isn't recognized (the attempted execve(2) returned ENOEXEC), these  functions will  execute  the shell (/bin/sh) with the path of the file as its first argument.  (If this attempt fails, no further searching is done.)
 
RETURN VALUE
       If any of the exec() functions returns, an error will have occurred.  The return value is -1, and the
       global variable errno will be set to indicate the error.
 
ERRORS
       All  of  these functions may fail and set errno for any of the errors specified for the library func-
       tion execve(2).
 
CONFORMING TO
       POSIX.1-2001.
 
NOTES
       On some other systems the default path (used when the environment does not contain the variable PATH) has  the  current  working directory listed after /bin and /usr/bin, as an anti-Trojan-horse measure.
       Linux uses here the traditional "current directory first" default path.
 
       The behavior of execlp() and execvp() when errors occur while attempting to execute the file is  historic practice, but has not traditionally been documented and is not specified by the POSIX standard.
       BSD (and possibly other systems) do an automatic sleep and retry if ETXTBSY  is  encountered.   Linux treats it as a hard error and returns immediately.
 
       Traditionally,  the  functions execlp() and execvp() ignored all errors except for the ones described above and ENOMEM and E2BIG, upon which they returned.  They now return if any error  other  than  the ones described above occurs.
 
SEE ALSO
       sh(1), execve(2), fork(2), ptrace(2), fexecve(3), environ(7)
 
COLOPHON
       This  page is part of release 2.79 of the Linux man-pages project.  A description of the project, and
       information about reporting bugs, can be found at




 SYSTEM(3)                                 Linux Programmer's Manual                                SYSTEM(3)
 
NAME
       system - execute a shell command
 
SYNOPSIS
       #include
 
       int system(const char *command);
 
DESCRIPTION
       system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed.  During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.
 
RETURN VALUE
       The value returned is -1 on error (e.g.  fork(2) failed), and the return status of the command otherwise.  This latter return status is in the format specified in wait(2).  Thus, the exit code  of  the command  will be WEXITSTATUS(status).  In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127).
 
       If the value of command is NULL, system() returns nonzero if the shell is available, and zero if not.
 
       system() does not affect the wait status of any other children.
 
CONFORMING TO
       C89, C99, POSIX.1-2001.
 
NOTES
       If  the  _XOPEN_SOURCE feature test macro is defined, then the macros described in wait(2) (WEXITSTA-
       TUS(), etc.) are made available when including .
 
       As mentioned, system() ignores SIGINT and SIGQUIT.  This may make programs that call it from  a  loop
       uninterruptible, unless they take care themselves to check the exit status of the child.  E.g.
 
           while (something) {
               int ret = system("foo");
 
               if (WIFSIGNALED(ret) &&
                   (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
                       break;
           }
 
       Do  not use system() from a program with set-user-ID or set-group-ID privileges, because strange values for some environment variables might be used to subvert system integrity.  Use the exec(3) family of functions instead, but not execlp(3) or execvp(3).  system() will not, in fact, work properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is bash  version  2, since  bash  2 drops privileges on startup.  (Debian uses a modified bash which does not do this when invoked as sh.)
 
       In versions of glibc before 2.1.3, the check for the availability of /bin/sh was  not  actually  performed  if  command  was  NULL;  instead  it  was always assumed to be available, and system() always returned 1 in  this  case.   Since  glibc  2.1.3,  this  check  is  performed  because,  even  though POSIX.1-2001 requires a conforming implementation to provide a shell, that shell may not be available or executable if the calling program has previously called  chroot(2)  (which  is  not  specified  by POSIX.1-2001).
 
       It  is  possible  for the shell command to return 127, so that code is not a sure indication that the execve(2) call failed.
 
       If the _XOPEN_SOURCE feature test macro is defined, then the macros described in  wait(2)  (WEXITSTATUS(), etc.) are made available when including .
 
SEE ALSO
       sh(1), signal(2), wait(2), exec(3)
 
COLOPHON
       This  page is part of release 2.79 of the Linux man-pages project.  A description of the project, and information about reporting bugs, can be found at
 
                                                 2004-12-20 
阅读(1055) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~