Guest User

Untitled

a guest
Jan 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. /* run-program-dots.c */
  2.  
  3. #include <sys/wait.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <signal.h>
  8.  
  9. int child_proc;
  10. void sigchild_handler(int signum)
  11. {
  12.         exit(0);
  13. }
  14. int main( int argc, char *argv[], char *envp[] )
  15. {
  16.     if( argc < 2 ) {
  17.         printf( "Insufficient arguments.\n" );
  18.         return -1;
  19.     }
  20.  
  21.     struct sigaction act;
  22.     act.sa_handler = sigchild_handler;
  23.  
  24.     child_proc = fork();
  25.     if(child_proc == 0) {
  26.         execve(argv[1] , argv + 1 ,NULL);
  27.     } else {
  28.         sigaction(SIGCHLD, &act, NULL);
  29.         while(1) {
  30.             sleep(1);
  31.             printf(".");
  32.             fflush(stdout);
  33.         }
  34.     }  
  35.     return 0;
  36. }
Add Comment
Please, Sign In to add comment