Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8. int i;
  9. int delay;
  10. char name[255],time[10],laun[255];
  11. FILE *fd;
  12. pid_t pid;
  13. fd=fopen(argv[1],"r");
  14. while(1)
  15. {
  16. if(fgetc(fd)==EOF)
  17. break;
  18. else
  19. fseek(fd,-1,SEEK_CUR);
  20. fscanf(fd,"%10s",&time);
  21. fseek(fd,1,SEEK_CUR);
  22. fgets(name,255,fd);
  23. delay=atoi(time);
  24. for(i=0;i<255;i++)
  25. laun[i]='\0';
  26. for(i=0;i<strlen(name)-1;i++)
  27. laun[i]=name[i];
  28. pid=fork();
  29. if(pid<0)
  30. {
  31. perror("fork() failed");
  32. return -1;
  33. }
  34. if(pid==0)
  35. {
  36. sleep(delay);
  37. execlp(laun,laun,NULL);
  38. perror("execlp() failed");
  39. return -1;
  40. }
  41. }
  42. fclose(fd);
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement