1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
int main (int argc, char* argv[])
{ char * fich[argc-1];
int status,i, j=0;
for (i=1 ; i<=argc; i++)
{ if ( fork() ==0)
{ execlp (argv[i], argv[i], NULL);
exit(3);
}
wait(&status);
if( (status>>8)==3)
{ fich[j] = new char[strlen(argv[i])+1];
strcpy(fich[j],argv[i]);
j++;
}
}
// Affichage des programmes non exécutés
cout << "Nombre de programmes non exécutés :" << j << endl;
if(j!=0)
{ cout << "Liste de programmes non exécutés : \n";
for (i=0; i<j; i++) cout << fich[i] << endl;
}
return 0;
} |
Partager