Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <string.h>
- #include <fcntl.h>
- main(int argc, char *argv[])
- {
- pid_t waitpid, childpid;
- int fh1;
- int status;
- fh1 = open(argv[1], O_RDONLY);//проверка тебе вроде как не нужна
- if (fh1 == -1)
- {
- printf(" invalid filename\n");
- return -1;
- }
- else
- {
- printf(" file exists\n");
- }
- childpid=fork();
- if(childpid==0)
- {
- /*Child's code*/
- printf("waiting 5 sec \n");
- sleep(5);
- //execv(argv[1],argv);
- //твой код
- }
- waitpid=wait(&status);
- printf("waitpid %d\n", waitpid);
- printf("status %d\n", status);
- if(WIFEXITED(status)==1)
- {
- printf(" child ended normally with WEXITSTATUS=%d\n",WEXITSTATUS(status));
- }
- else
- {
- printf(" child ended not normally\n");
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement