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 i;
- pid_t processes[MAXFILS];
- for (i=0; i<MAXFILS ; i++) processes = 0; //INITIALISATION
- int avancement = 2;
- while (avancement < argc) {
- for (i = 0; i<MAXFILS && avancement < argc; i++) {
- if (processes[i] == 0 || !kill(processes[i], 0) { //PROCESSUS INACTIF
- pid_t pid = fork();
- if(pid == 0){
- execl("/bin/grep", "grep", argv[1], argv[i], NULL);
- avancement++;
- exit(1);
- }
- else{
- processes[i] = pid;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement