Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <math.h>
  2. #include <sys/types.h>
  3. #include <sys/shm.h>
  4. #include <sys/ipc.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include <stdlib.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <sys/sem.h>
  11. #include <string.h>
  12.  
  13. int main()
  14. {
  15.  
  16. int fd, N;
  17. char string[5000];
  18. //----------------------------------------------
  19. if ( (fd = open("text.txt", O_RDONLY)) < 0)
  20. {
  21. perror("open");
  22. exit(-1);
  23. }
  24.  
  25. if ((N = read(fd, string, 5000)) < 0)
  26. {
  27. perror("read");
  28. exit(-1);
  29. }
  30.  
  31. close(fd);
  32. //---------------------------------------------
  33. int j = 0;
  34. int k = 0;
  35. int a = 0;
  36. int h[5];
  37. int time[15];
  38. char name[50][15];
  39.  
  40. for (int i = 0; i < N; i++)
  41. {
  42. if (string[i] <= '9' && (int)string[i] >= '0')
  43. {
  44. a = 0;
  45. h[j] = (int)string[i] - (int)'0';
  46. j++;
  47.  
  48. }
  49. else if (string[i] == ' ')
  50. {
  51. for(int l = 0; l < j; l++)
  52. {
  53. time[k] += h[l] * pow(10, j - l - 1);
  54. }
  55. k++;
  56. }
  57. else if (string[i] != '\n')
  58. {
  59. while(string[i] != '\n')
  60. {
  61. j = 0;
  62. name[k-1][a] = string[i];
  63. a++;
  64. i++;
  65. }
  66. }
  67.  
  68. }
  69. //--------------------------------------------------------------
  70.  
  71. for (int i = 0; i < k; i++)
  72. {
  73. int pid;
  74. pid = fork();
  75. if(pid != 0)
  76. {
  77. sleep(time[0]);
  78. char path[100];
  79. strcat(path,"/home/alexey/");
  80. strcat( path, name[0]);
  81. execlp(path,name[0], NULL);
  82. }
  83. }
  84.  
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement