shared int between parent and child

This is a discussion on shared int between parent and child within the C Programming forums, part of the General Programming Boards category; Hi all, whats the best method of sharing a variable between a child and a parent? specifically I want the ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    shared int between parent and child

    Hi all,

    whats the best method of sharing a variable between a child and a parent?

    specifically I want the parent to exit successfully only if the child has initialised properly, otherwise exit with an error as well as the child.

    TIA, rotis23

    Code:
    //share this memory between parent and child
    int confirm_ok = -1;
    
    switch (pid = fork())
    {
        case 0:
            //do some initilisation stuff
            confirm_ok = 0;
            daemon_loop();
            break;
        default;
            while(confirm_ok == -1)
            {
                  sleep(1);
            }
            if(confirm_ok == 1) 
                exit(EXIT_FAILURE);
            else
                exit(EXIT_SUCCESS);
    }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    ok thanks vVv, thats was I was after.

    my options were pipe or IPC, a lot of effort for the required functionality - hence why asked the question.

    i think i may go for the signals - it seems a more intuitive method. however, SIGUSR signals are a limited resource (only two) - i shall make sure i won't be using them in the future before using this method!

    thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  2. Replies: 3
    Last Post: 10-15-2008, 10:24 AM
  3. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 08:53 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21