Assume I have the following code.
int main(int argc, char* argv[])
{
char* program[3] = {"/bin/ls", NULL, NULL};
pid_t pid = fork();
if (pid == 0) {
char* envp[1] = {NULL};
execve(program[0], program, envp);
}
int status;
printf("Going to wait for process with pid: %d\n", pid);
waitpid(pid, &status, 0);
return 0;
}
if I execute it, it terminates just fine.
But, if I do "ls -l" (just changing the program array) instead of "ls" it halts forever. So this program
int main(int argc, char* argv[])
{
char* program[3] = {"/bin/ls", "-l", NULL};
pid_t pid = fork();
if (pid == 0) {
char* envp[1] = {NULL};
execve(program[0], program, envp);
}
int status;
printf("Going to wait for process with pid: %d\n", pid);
waitpid(pid, &status, 0);
return 0;
}
Any idea on why this is happening?