Hello guys!
I am doing a project for the university and I have to do that a process has to create several children through fork(). The father process sends a pathname to each one through exec and the children must send to the father a list with the files from each directory.
The father is waiting and the children don't send anything. I must to do the pipe with mkfifo. I am trying to send text from the children but nothing happens. This is the code that I have wroten:
struct stat buf;
mkfifo(NOMBREFIFO, S_IRWXU);
while (--argc>0){
stat (argv[argc], &buf);
if (S_ISDIR(buf.st_mode)){
pid = fork();
if (pid<0) fprintf (stderr, "error %d", errno);
if (pid==0) printf ("hhhhhhhhh");
if (pid==0 && (exec=execl ("./listarordenado", argv[argc], NULL))<0) fprintf (stderr, "error %d", errno);
if (pid>0 && wait(&status) && waitpid (pid, &status, 0)){
printf ("ssssssssss");
while(TRUE) {
fp=open(NOMBREFIFO,O_RDONLY);
nbytes=read(fp,buffer,TAM_BUF-1);
buffer[nbytes]='\0';
printf("%d Cadena recibida: %s \n",i, buffer);
close(fp);
i++;
}
}
}
}
/////***code of listarordenado*//
for (i=0; i<50; i++){
if ((fp=open(NOMBREFIFO,O_WRONLY))==-1)
perror("fopen");
else {
descr=write(fp,argv[1],strlen(argv[1]));
}
close(fp);
}
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University: Universidad de Castilla-La Mancha (Ciudad Real, spain)
Professor: Carlos Gonzalez Morcillo :: Personal Web Page www. inf-cr.uclm.es/www/cglez/
Degree: "Computer engineering"
Subject: "Ampliaci�n de Sistemas Operativos" + info: www. esi.uclm.es:8081/www/GuiaDocente/GuiaDocente0910/guias/42534_0910.pdf