Chapter Contents

Previous

Next
execvp

execvp



Overlay Calling Process and Run New Program

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <unistd.h>

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


DESCRIPTION

Like all of the exec functions, execvp replaces the calling process image with a new process image. This has the effect of running a new program with the process ID of the calling process. Note that a new process is not started; the new process image simply overlays the original process image. The execvp function is most commonly used to overlay a process image that has been created by a call to the fork function.

path
identifies the location of the new process image within the hierarchical file system (HFS). If the path argument contains a slash ( / ), it is assumed that either an absolute or a relative pathname has been specified. If the path argument does not contain a slash, the directories specified by the PATH environment variable are searched in an attempt to locate the file.

argv
is a pointer to an array of pointers to null-terminated character strings. A NULL pointer is used to mark the end of the array. Each character string pointed to by the array is used to pass an argument to the new process image. The first argument, argv[0] , is required and must contain the name of the executable file for the new process image.


RETURN VALUE

A successful call to execvp does not have a return value because the new process image overlays the calling process image. However, a -1 is returned if the call to execvp is unsuccessful.


EXAMPLE

The following example illustrates the use of execvp to execute the ls shell command:

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

main()

{
   pid_t pid;
   char *const parmList[] = 
   {"/bin/ls", "-l", "/u/userid/dirname", NULL\};

   if ((pid = fork()) == -1)
      perror("fork() error");
   else if (pid == 0) \{
      execvp("ls", parmList);
      printf("Return not expected. Must be an execvp() error.\\n");
   }
}


RELATED FUNCTIONS

execlp , execv


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.