C   68

forkexec lala

Guest on 1st June 2022 01:34:03 AM

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  6. char *lala = "lalala\n";
  7. char *nothing = 0;
  8.  
  9. int
  10. main(int argc, char *argv[])
  11. {
  12.   int status;
  13.   int rc = fork();
  14.   if (rc < 0) {
  15.     perror("fork failed: ");
  16.     exit(1);
  17.   } else if (rc == 0) {
  18.     argv++;
  19.     execve(argv[0], argv, &lala);
  20.   } else {
  21.     waitpid(rc, &status, 0);
  22.     printf("child %d exited with status %d\n", rc,
  23.            WEXITSTATUS(status));
  24.   }
  25. }

Raw Paste


Login or Register to edit or fork this paste. It's free.