hello guys,
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
void
main(int argc, char *argv[])
{
int status;
char *prog = argv[0];
char *new_cmd = "/bin/echo";
char *cmd_args[] = {"echo", "hello", "world", NULL};
char *cmd_env[] = {NULL};
status = execve(new_cmd, cmd_args, cmd_env);
/*
* execve does not return unless there is an error.
*/
fprintf(stderr, "%s: ", prog);
perror("execve");
exit(1);
}
A sample run of this program gives the following output:
> ./sys2
hello world
>
what i understood is that this process wants to execute another process.
i googled and find that. execve takes three arguments: a filename to be executed, an array of strings which are the arguments to the filename, and an array of strings which represent the environment for the process.
but i still dont understand how we got this input .
id appreciate it if anybody can explain it line by line.