Implement the ExecV system call.
ExecV is like Exec, except that it allows an array
of parameters to be passed to the newly created process.
From syscall.h:
/* Run the executable, stored in the Nachos file "argv[0]", with * parameters stored in argv[1..argc-1] and return a * unique non-negative process identifier for the new process. * Returns a negative value in case of failure. * * A few example error codes might be: * NACHOS_ENAMETOOLONG path to executable uses too many characters * NACHOS_EREACHEDLIMIT too many arguments to handle properly * NACHOS_EINVAL one or more arguments is not valid */ ProcessId ExecV(int argc, char* argv[]);
#include "syscall.h" int main(int argc, char *argv[]) { int i; for (i=0; i<argc; i++) { print("Arg "); printInt(i); print(" = "); print(argv[i]); print("\n"); } Exit(0); }So for example if another program starts the program above as follows:
char *pgm = "PrintArgs"; char *arg1 = "1"; char *arg2 = "2"; char *arg2 = "arg3"; char *arg3 = "thatsall"; char *arglist[5]; arglist[0] = pgm; arglist[1] = arg1; arglist[2] = arg2; arglist[3] = arg2; arglist[4] = arg3; ExecV(5, arglist);Would result in the following output:
Arg 0 = PrintArgs Arg 1 = 1 Arg 2 = 2 Arg 3 = arg3 Arg 4 = thatsall