|
|
coherent
execve() COHERENT System Call execve()
Execute a load module
eexxeeccvvee(_f_i_l_e, _a_r_g_v, _e_n_v)
cchhaarr *_f_i_l_e, *_a_r_g_v[], *_e_n_v[];
The COHERENT system includes six functions that allow a process
to execute another executable file (or load module, as described
in the header l.out.h). execve specifies arguments as a single,
NULL-terminated array of parameters, called argv. The argument
env is the address of an array of pointers to strings that define
file's environment. This allows execve to pass a new environment
to the program being executed. For more information on program
execution, see execl.
***** Example *****
The following example demonstrates execve, as well as tmpnam,
getenv, and path. It finds all lines with more than LIMIT
characters and call MicroEMACS to edit them.
#include <stdio.h>
#include <path.h>
#include <sys/stat.h>
#define LIMIT 70
extern char *getenv(), **environ, *tempnam();
main(argc, argv)
char *argv[];
{
/* me -e tmp file */
char *cmda[5] = { NULL, "-e", NULL, NULL, NULL };
FILE *ifp, *tmp;
char line[256];
int ct, len;
if ((NULL == (cmda[3] = argv[1])) ||
(NULL == (ifp = fopen(argv[1], "r")))) {
fprintf(stderr, "Cannot open %s\n", argv[1]);
exit(1);
}
COHERENT Lexicon Page 1
execve() COHERENT System Call execve()
if (cmda[0] = path(getenv("PATH"), "me", AEXEC) == NULL) {
fprintf(stderr, "Cannot locate me\n");
exit(1);
}
if (NULL == (tmp = fopen((cmda[2] = tempnam(NULL, "lng")), "w"))) {
fprintf(stderr, "Cannot open tmpfile\n");
exit(1);
}
for (ct = 1; NULL != fgets(line, sizeof(line), ifp); ct++)
if (((len = strlen(line)) > LIMIT) ||
('\n' != line[len -1]))
fprintf(tmp, "%d: %d characters long\n", ct, len);
fclose(tmp);
fclose(ifp);
if (execve(cmda[0], cmda, environ) < 0) {
fprintf(stderr, "cannot execute me\n");
exit(1);
}
/* We never reach here ! */
}
***** See Also *****
COHERENT system calls, environ, execution
***** Diagnostics *****
execve does not return if successful. It returns -1 for errors,
such as file being nonexistent, not accessible with execute per-
mission, having a bad format, or too large to fit in memory.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.