/* A quick example using exec to demonstrate shell execution w vfork */ /* Run it to screen, and then redirect to file. Is the output different? */ #include #include main() {int status; if (vfork()==0) { /* Use vfork to force child to go first-same if fork */ pid_t pid=getpid(); printf("Child's pid is %d\n",pid); printf("No Path Search - Full display\n"); execl("/bin/ls","/bin/ls","-l",NULL); // Uncomment to see if parent waits after start of exec // execlp("sleep","sleep","5",NULL); // execlp("ps","ps",NULL); // Uncomment to see pid while executing } else { // parent printf("Parent Process Resumes \n"); pid_t pid=wait(&status); printf("Child PID %d Returned with Status %d\n",pid,status); exit(0); } }