Thread: manage processes

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    29

    manage processes

    (Using C on ubuntu)

    In my program I need to fork a process and execute a .bin in the child process. Then I want to create a pipe that "connects" the stdout of the child to the stdout of the parent. I know basically how to do this using write() and read() in the pipes.
    The problem is that the parent should wait until the child sends a specific message (a string), or until a timeout occurs. In the first case both processes should run in "parallel" ( I don't know if its the correct term..), in the second case the child must abort and the parent go on. And I don't have a clue how to accomplish any of this things. Any suggestions ?

    I made a very basic skeleton, comments?


    Code:
     int status;
        int fd[2]; /* pipe */
    
        if( pipe(fd) !=0 )
        {
          perror("Failed to create pipe");
          exit(EXIT_FAILURE);
        }
    
        pid_t pid=fork();
    
        if( pid<0)
        {
          perror("Failed to fork");
          exit(EXIT_FAILURE);
        }
    
        else if(pid == 0) /* child */
        {
          if(execl("/usr/bin/sixad","sixad","-s",NULL)==-1);
          perror("Child unabled to start sixad");
    
          exit(EXIT_FAILURE);
        }
    sorry for the cross posting in the linux forum. I ask the moderators to eliminate the other post please.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. Processes not dying
    By Elkvis in forum Linux Programming
    Replies: 12
    Last Post: 04-23-2008, 08:59 AM
  3. Problems defining classes
    By esmeco in forum C++ Programming
    Replies: 47
    Last Post: 10-24-2007, 01:13 PM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. Computer Processes.... Which can be stopped?
    By Sevrin in forum Tech Board
    Replies: 3
    Last Post: 06-08-2003, 08:13 PM