Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- int main(int argc,char *argv[])
- {
- int i;
- int delay;
- char name[255],time[10],laun[255];
- FILE *fd;
- pid_t pid;
- fd=fopen(argv[1],"r");
- while(1)
- {
- if(fgetc(fd)==EOF)
- break;
- else
- fseek(fd,-1,SEEK_CUR);
- fscanf(fd,"%10s",&time);
- fseek(fd,1,SEEK_CUR);
- fgets(name,255,fd);
- delay=atoi(time);
- for(i=0;i<255;i++)
- laun[i]='\0';
- for(i=0;i<strlen(name)-1;i++)
- laun[i]=name[i];
- pid=fork();
- if(pid<0)
- {
- perror("fork() failed");
- return -1;
- }
- if(pid==0)
- {
- sleep(delay);
- execlp(laun,laun,NULL);
- perror("execlp() failed");
- return -1;
- }
- }
- fclose(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement