#include #include #include #include #include #include extern char **environ; int main(void) { pid_t pid; int stat; printf("Parent process (%d) starts ...\n", getpid()); if ((pid = fork()) != 0) { printf("Parent is waiting ...\n"); pid = wait(&stat); if(WIFEXITED(stat)){ printf("Exit Status was %d\n",WEXITSTATUS(stat)); } } else { printf("Child process (%d) has parent %d\n", getpid(), getppid()); char *args[3] = {"/usr/bin/ls","-l", NULL} ; stat = execve(args[0], args, environ); printf("In child %d\n",stat); // only reach here if exec fails perror("Exec failed"); return 1; } return 0; }