Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <errno.h>
  5. #include <sys/wait.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <fcntl.h>
  9.  
  10. main(int argc, char *argv[])
  11. {
  12.     pid_t waitpid, childpid;
  13.     int fh1;
  14.     int status;
  15.     fh1 = open(argv[1], O_RDONLY);//проверка тебе вроде как не нужна
  16.     if (fh1 == -1)
  17.     {
  18.         printf(" invalid filename\n");
  19.         return -1;
  20.     }
  21.     else
  22.     {
  23.         printf(" file exists\n");
  24.     }
  25.     childpid=fork();
  26.     if(childpid==0)
  27.         {
  28.             /*Child's code*/
  29.             printf("waiting 5 sec \n");
  30.             sleep(5);
  31.             //execv(argv[1],argv);
  32.             //твой код
  33.         }
  34.     waitpid=wait(&status);
  35.     printf("waitpid %d\n", waitpid);
  36.     printf("status %d\n", status);
  37.     if(WIFEXITED(status)==1)
  38.     {
  39.         printf(" child ended normally with WEXITSTATUS=%d\n",WEXITSTATUS(status));
  40.     }
  41.     else
  42.     {
  43.         printf(" child ended not normally\n");
  44.     }
  45.     return;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement