execv - execute a program
Standard C Library (libc, -lc)
#include <unistd.h>
int
execv(const char *program,
char **args);
int
execve(const char *program,
char **args,
char **environ);
execv replaces the currently executing program with a newly loaded program image. This occurs within one process; the process id is unchanged.
The pathname of the program to run is passed as program. The args argument is an array of 0-terminated strings. The array itself should be terminated by a NULL pointer.
The argument strings should be copied into the new process as the new process's argv[] array. In the new process, argv[argc] must be NULL.
By convention, argv[0] in new processes contains the name that was used to invoke the program. This is not necessarily the same as program, and furthermore is only a convention and should not be enforced by the kernel.
The process file table and current working directory are not modified by execv.
The execve call is the same as execv except that a NULL-terminated list of environment strings (of the form var=value) is also passed through. In Unix, execv is a small wrapper for execve that supplies the current process environment. In OS/161, execv is the primary exec call and execve is not supported or needed unless you put in extra work to implement it.
The maximum total size of the argv (and environment, if any) data is given by the system constant ARG_MAX. This comes set to 64K by default. You may change this limit, but don't reduce it without asking your course staff. The fact that argv blocks can be large is part of the design problem; while it's possible to set the limit to 4K and still have most things work, you are probably supposed to put at least some thought into engineering a real solution. (One problem to consider is that after the system has been up a while and system memory starts to become fragmented, you still need to be able to allocate enough memory to handle exec. Another is to make sure the system doesn't choke if too many processes are trying to exec at once. There are lots of ways to tackle this; be creative.)
Whether the size of the pointers appearing in the argv array count towards the ARG_MAX limit is implementation-defined. Either way it should be possible to pass a lot of small arguments without bumping into some other limit on the number of pointers.
On success, execv does not return; instead, the new program begins executing. On failure, execv returns -1, and sets errno to a suitable error code for the error condition encountered.
The following error codes should be returned under the conditions given. Other error codes may be returned for other errors not mentioned here.
ENODEV | The device prefix of program did not exist. | |
ENOTDIR | A non-final component of program was not a directory. | |
ENOENT | program did not exist. | |
EISDIR | program is a directory. | |
ENOEXEC | program is not in a recognizable executable file format, was for the wrong platform, or contained invalid fields. | |
ENOMEM | Insufficient virtual memory is available. | |
E2BIG | The total size of the argument strings exceeeds ARG_MAX. | |
EIO | A hard I/O error occurred. | |
EFAULT | One of the arguments is an invalid pointer. |