Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*в текущей директории нужно создать файл inf.txt. В нем через пробел задержка,имя исполняемого файла
- (если он находится в текущей директории или полный путь иначе).Файл заканчивается enter'ом. */
- #include <unistd.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdlib.h>
- int main (){
- int fd1;
- int t=0,i=0,flag=0,j=0;
- size_t size;
- char buf1[10];
- char buf2[100];
- fd1=open ("inf.txt",O_RDONLY);
- if (fd1<0){printf ("Error");}
- while (1){
- read(fd1,buf1,1);
- buf2[i]=buf1[0];
- if (flag==1 && (buf1[0]==' '||buf1[0]=='\n')){
- buf2[i]='\0';
- if(fork()==0){sleep(t);execv(buf2,0);}
- //printf ("%c %i\n",buf1[0],t);
- if (buf1[0]=='\n'){break;}
- for (j=0;j<i;j++){buf2[j]='\0';}
- i=-1;flag=0;goto qw;}
- if (flag==0 && buf1[0]==' '){
- buf2[i]='\0';
- t=atoi(buf2);
- for (j=0;j<i;j++){buf2[j]='\0';}
- flag=1;i=-1;}
- if (buf1[0]=='\n'){break;}
- qw:
- i=i+1;
- }
- close (fd1);
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement