Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7.  
  8. int main()
  9. {
  10.  
  11. FILE* fi;
  12. int time[15];
  13. char name[50][15];
  14. //----------------------------------------------
  15. fi = fopen("text.txt", "r");
  16. int i = 0;
  17. while(fscanf(fi, "%d %s\n", &time[i], name[i]) == 2)
  18. {
  19. i++;
  20. }
  21. fclose(fi);
  22. //--------------------------------------------------------------
  23.  
  24. for (int k = 0; k < i; k++)
  25. {
  26. int pid;
  27. pid = fork();
  28. if(pid != 0)
  29. {
  30. sleep(time[k]);
  31. char path[100];
  32. strcat(path,"/home/alexey/");
  33. strcat( path, name[k]);
  34. execlp(path,name[k], NULL);
  35. }
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement