Say I want to start a process and run execv to execute a command like ls , then I will do this:
char * const parm[] = { "/usr/bin/ls","-l" , NULL }; if ((pid = vfork()) == -1) perror("fork error"); else if (pid == 0) { execv("/usr/bin/ls", parm); }
Now the question arises that here I am hard-coded, where the ls ( /usr/bin/ls ) is present. Now suppose that I donβt know where any particular command is present and wants to execute it, then how can I do it? I know that in a normal shell, the PATH variable is checked to achieve the same, but in the case of a C program using execv , how can I achieve it?
source share