Question Details

No question body available.

Tags

c system-calls execve

Answers (2)

July 21, 2026 Score: 7 Rep: 235,424 Quality: Medium Completeness: 50%

The path parameter isn't for passing the PATH environment variable. It's for passing the path to your program.

For example, if your program resides as /path/to/program and you want to pass it "aa", "bb", and "cc" as parameters, you would call execve as follows:

char *args[] = {"program_name", "aa", "bb", "cc", NULL}; execve("/path/to/program", args, NULL); // if you get here, execve failed perror("execve failed");
July 21, 2026 Score: 1 Rep: 123,312 Quality: Low Completeness: 50%

There are two different meanings of the word path, one is roughly synonymous with filename and the other one is a list of directories to be searched. The PATH environment variable uses the second sense of the word. You need the first sense, so you need to find out which executable file runs the ls command. Usually it's /bin/ls.

If you want to use just ls, execvp and execvpe are your friends. The letter p in the names of these functions stands for the PATH environment variable.