Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <sys/types.h>
- #include <sys/shm.h>
- #include <sys/ipc.h>
- #include <stdio.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/sem.h>
- #include <string.h>
- int main()
- {
- int fd, N;
- char string[5000];
- //----------------------------------------------
- if ( (fd = open("text.txt", O_RDONLY)) < 0)
- {
- perror("open");
- exit(-1);
- }
- if ((N = read(fd, string, 5000)) < 0)
- {
- perror("read");
- exit(-1);
- }
- close(fd);
- //---------------------------------------------
- int j = 0;
- int k = 0;
- int a = 0;
- int h[5];
- int time[15];
- char name[50][15];
- for (int i = 0; i < N; i++)
- {
- if (string[i] <= '9' && (int)string[i] >= '0')
- {
- a = 0;
- h[j] = (int)string[i] - (int)'0';
- j++;
- }
- else if (string[i] == ' ')
- {
- for(int l = 0; l < j; l++)
- {
- time[k] += h[l] * pow(10, j - l - 1);
- }
- k++;
- }
- else if (string[i] != '\n')
- {
- while(string[i] != '\n')
- {
- j = 0;
- name[k-1][a] = string[i];
- a++;
- i++;
- }
- }
- }
- //--------------------------------------------------------------
- for (int i = 0; i < k; i++)
- {
- int pid;
- pid = fork();
- if(pid != 0)
- {
- sleep(time[0]);
- char path[100];
- strcat(path,"/home/alexey/");
- strcat( path, name[0]);
- execlp(path,name[0], NULL);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement