Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <limits.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <errno.h>
- #include <string.h>
- #include <ctype.h>
- char makeargv(char *caracteres)
- {
- char argumentos[3][30];
- int i=0,j=0;
- while(*caracteres!='\0')
- {
- if(*caracteres==' ')
- j++;
- argumentos[j][i++]=*caracteres++;;
- }
- return argumentos;
- }
- int main(int argc, char *argv[])
- {
- int i,n, status, pr_limit, pr_count=0;
- char cadena[MAX_CANON],argumentos[3][100];
- if (isdigit(argv[1])==0)
- {
- fprintf(stderr, "ERROR FATAL");
- exit(0);
- }
- pr_limit=atoi(argv[1]);
- pid_t childpid;
- FILE *fd;
- fd=fopen( "testsim.data", "r");
- for(i=1; i<pr_limit; i++)
- {
- if (pr_count==pr_limit)
- {wait(&status);
- pr_count--;
- }
- fgets(cadena,MAX_CANON,fd);
- argumentos=makeargv(cadena);
- switch(fork())
- {
- case -1: exit(0);
- case 0: break;
- default: execvcp(argumentos[0],argumentos);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement