Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    1

    Help with Mkfifo and exec


    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:


    Code:
    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);
        }

    thanks,
    daniel

  2. #2
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,864
    Hello and Welcome to the forums.
    While we do encourage students to learn Linux as much as they desire, I think this "project" is a homework assignment and is also in violation of forum rules.
    http://www.linuxforums.org/forum/lin...ums-rules.html
    Rule 2) no homework questions.
    If someone answers the question for you, then you really haven't learned anything.
    You may send a PM to any super moderator or trusted penguin if you feel this thread should not be locked.
    *locking*
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •