Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #define MAXFILS 3
- int main(int argc, char* argv[]){
- if(argc < 3){
- printf("Syntaxe : ./ex3 chaîne <liste_fichiers>\n");
- return 0;
- }
- int pid;
- int processes = 0;
- int avancement = 2;
- while (avancement < argc) {
- while(processes < MAXFILS){
- processes++;
- pid = fork();
- if (pid == 0){
- execl("/bin/grep", "grep", argv[1], argv[avancement], NULL);
- exit()
- }
- else {
- wait(NULL);
- processes--;
- }
- avancement++;
- if (avancement == argc) break;
- }
- wait(NULL);
- processes--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement