previous | start | next

Example (parent: fork + execlp)

    1   
    2   #include <stdio.h>
    3   #include <stdlib.h>
    4   #include <unistd.h>
    5   #include <sys/wait.h>
    6   #include <sys/types.h>
    7   #include <signal.h>
    8   
    9   int main(int argc, char* argv[])
   10   {
   11     pid_t pid;
   12   
   13     int status;
   14     char str[32];
   15     printf("Enter a letter: ");
   16     scanf("%s", str);
   17   
   18     if ( (n = fork()) == 0 ) {
   19       execlp("printCh", "printCh", str, (char *) 0);
   20       printf("Unable to execute printCh\n");
   21       exit(0);
   22     }
   23   
   24     pid = waitpid(-1, &status, 0);
   25     if ( WIFEXITED(status) ) {
   26       printf("child %d exited with status = %d\n", pid,
   27     WEXITSTATUS(status));
   28     }
   29   
   30     return 0;
   31   }


previous | start | next