Inter process communication

Discussion in 'Ruby' started by Peter Lom, Aug 20, 2008.

  1. Peter Lom

    Peter Lom Guest

    Hi,

    please advise on the following.

    Need to implement execution of tasks in serial and parallel mode
    together with daemons within Ruby.

    Scenario:
    The main program starts with a fork - it executes in the child process
    some background programs in the strict sequence - need to leave this
    child process running as a daemon.
    When the last program announces that it finished init stage, it writes a
    notice to the stdout (I cannot modify this notice but I know what is
    it);
    - how to advise the parent that all is ready?

    I use Program.detach to continue in the main - all is OK but I don't
    know when the last daemon finishes init and wrote that notice (use of
    sleep works but is ugly)


    When the parent knows all is ready, it should start launching new set of
    tasks in serial or parallel mode.

    I execute serial tasks in a separate thread and all works OK.

    How can the parent know if parallel tasks finished?
    Do I need semaphores/mutexes etc to organise this?


    Many thanks
    Peter
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Lom, Aug 20, 2008
    #1
    1. Advertising

  2. Peter Lom wrote:
    > Hi,
    >
    > please advise on the following.
    >
    > Need to implement execution of tasks in serial and parallel mode
    > together with daemons within Ruby.
    >
    > Scenario:
    > The main program starts with a fork - it executes in the child process
    > some background programs in the strict sequence - need to leave this
    > child process running as a daemon.
    > When the last program announces that it finished init stage, it writes a
    > notice to the stdout (I cannot modify this notice but I know what is
    > it);
    > - how to advise the parent that all is ready?
    >
    > I use Program.detach to continue in the main - all is OK but I don't
    > know when the last daemon finishes init and wrote that notice (use of
    > sleep works but is ugly)
    >
    >
    > When the parent knows all is ready, it should start launching new set of
    > tasks in serial or parallel mode.
    >
    > I execute serial tasks in a separate thread and all works OK.
    >
    > How can the parent know if parallel tasks finished?
    > Do I need semaphores/mutexes etc to organise this?
    >
    >
    > Many thanks
    > Peter


    You have a few options.

    You can use popen to run the daemon script, which will puts a message
    that the parent program will gets. The popen method uses fork/exec
    internally, so it will be in a separate process.

    You can fork another process and use UNIX signals to signal the parent
    it's ready. I'm not sure if Ruby can use the pause syscall and it will
    probably only work on *nix.

    Run the commands and then fork into parent program and daemon. This
    means you won't need another mechanism to notify the parent the commands
    have been run at all.

    --
    Michael Morin
    Guide to Ruby
    http://ruby.about.com/
    Become an About.com Guide: beaguide.about.com
    About.com is part of the New York Times Company
     
    Michael Morin, Aug 20, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Knute Johnson
    Replies:
    0
    Views:
    829
    Knute Johnson
    Jun 27, 2003
  2. Jon A. Cruz
    Replies:
    0
    Views:
    739
    Jon A. Cruz
    Jun 28, 2003
  3. Sudsy
    Replies:
    0
    Views:
    965
    Sudsy
    Jun 28, 2003
  4. Frank D. Greco
    Replies:
    1
    Views:
    2,211
    Keeger
    Jun 30, 2003
  5. Hugo Ferreira
    Replies:
    0
    Views:
    798
    Hugo Ferreira
    Dec 4, 2006
Loading...

Share This Page