Advertisement
piffy

Fork-exec (base)

Aug 23rd, 2014
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>        
  6. int main () {    
  7.        int status=0;
  8.        pid_t pid;
  9.  
  10.        pid = fork ();
  11.        if (pid == 0)
  12.          {
  13.            /* Questo è il figlio, che lancia gedit */
  14.            execl("/usr/bin/gedit", "gedit", NULL);
  15.            _exit (EXIT_FAILURE);
  16.          }
  17.        else if (pid < 0)
  18.          /* Fork fallito.  */
  19.          status = -1;
  20.        else
  21.          /* Questo è il genitore, che aspetta che il figlio termini
  22.           * status e'il valore di ritorno dell'altro processo */
  23.          wait(&status);
  24.        return EXIT_SUCCESS;
  25.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement