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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main (void){
int p[2];
int fdfile,fdresults;
int status;
if(pipe(p)==-1){
perror("pipe");
exit(1);
}
switch(fork()){
case -1 :
perror("fork");
exit(2);
case 0:
fdfile = open("file", O_RDONLY);
dup2(fdfile, 0);
dup2(p[1], 1);
close(p[0]);
execlp("exe1", "exe1", "-O", NULL) ;
perror("execlp" );
exit(3);
default:
fdresults = open("results", O_WRONLY|O_CREAT|O_APPEND, 0666);
dup2(fdresults, 1);
dup2(p[0], 0);
close(p[1]);
execlp("exo4", "exo4", "-lix", NULL) ;
perror("execlp" );
exit(4);
}
close(p[0]);
close(p[1]);
} |
Partager