#include #include #include #include #include #include int main() { int status; int pid; char *prog_argv[4]; /* * Build argument list */ /* Remove the path or make the path correct for your system, as needed */ prog_argv[0] = "/usr/local/bin/ls"; prog_argv[1] = "-l"; prog_argv[2] = "/"; prog_argv[3] = NULL; /* * Create a process space for the ls */ if ((pid=fork()) < 0) { perror ("Fork failed"); exit(errno); } if (!pid) { /* This is the child, so execute the ls */ execvp (prog_argv[0], prog_argv); } if (pid) { /* * We're in the parent; let's wait for the child to finish */ waitpid (pid, &status, 0); } return 0; }