Exec... series Functions
L series:
Int execl (char * path, char * arg0, char * arg1,..., null );
Int execlp (char * path, char * arg0, char * arg1,..., null );
Int execle (char * path, char * arg0, char * arg1,..., null, char ** envp
);
Int execlpe (char * path, char * arg0, char * arg1,..., null, char ** envp
);
V series:
Int execv (char * path, char * Arg []);
Int execvp (char * path, char * Arg []);
Int execve (char * path, char * Arg []
, Char ** envp
);
Int execvpe (char * path, char * Arg []
, Char ** envp
);
Note: The prototype is in process. h.
Exec... series functions can load and run other files called Child processes. When the call is successful, the child process overwrites the parent process.
Sufficient memory is required.
*
PATH is the name of the called sub-process.
The exec... function is searched through the standard DoS search algorithm.
Path:
1. If the wood has an extension or a period: Search for the name first. If no extension is found, add .com, and find the extension later.
2. If the extension is specified, search for the specified file directly.
3. If a period is given, search for files without an extension.
4. If path does not contain a specified directory
The exec... function is first searched in the current directory,
If no directory is found, search for the directory specified by the DOS environment variable path.
# Include <process. h>
# Include <stdio. h>
# Include <errno. h>
Void main (INT argc, char * argv [])
{
Int I;
Printf ("command line arguments:/N ");
For (I = 0; I <argc; I ++)
Printf ("[% 2D]: % s/n", I, argv [I])
;
Printf ("about to Exec child with arg1 arg2.../N ");
Execvp ("H: // output // ten2bin.exe"
, Argv );
Perror ("execv error ");
Exit (1 );
}
# Include <process. h>
# Include <stdio. h>
# Include <errno. h>
Void main (INT argc, char * argv [])
{
Int I;
Printf ("command line arguments:/N ");
For (I = 0; I <argc; I ++)
Printf ("[% 2D]: % s/n", I, argv [I]
);
Printf ("about to Exec child with arg1 arg2.../N ");
Execvp ("ten2bin.exe"
, Argv );
Perror ("execv error ");
Exit (1 );
}
The suffixes L, V, p, and E after the exec... series functions indicate some operation capabilities of the naming function;
L:
It indicates that the pointer parameters arg0, arg1,... are passed as independent parameters. Generally, the L suffix is used to know the number of parameters to be passed in advance.
V:
It indicates that the needle tie parameter arg0], Arg [1],..., Arg [N] is passed as a pointer array. Generally, the V suffix is used when the number of parameters to be passed is variable.
P:
If no directory is specified, search for the file in the current directory first. If no directory is found, search for the file in the path specified by the Environment Variable path.
E:
It indicates that the parameter envp can be uploaded to the sub-process to change the environment of the sub-process. Without the E suffix, the child process inherits the environment of the parent process.
Exec...
A series of functions must pass at least one parameter (arg0 or Arg [0]) to the sub-process, which is a copy of path. Similar to main (INT argc,
In char * argv []), argv [0]. The null value after argn/ARG [N] indicates the end of the parameter table.
When the execution is successful, the returned value is the exit status of the sub-process (0 indicates the normal termination ). If the sub-process calls the exit function with a non-0 parameter, the exit status is not 0.
When an error occurs, the exec... function returns the value-1 and sets the global variable errno to one of the following.
The e2big parameter table is too long.
Eacces does not have this permission
Too many files are opened in emfile.
Enoent path or file name not found
Enoexec running format Error
Enomem does not have enough memory
Portability: Only applicable to DoS