How to create a semaphore for a file

Discussion in 'C++' started by azi, Aug 9, 2003.

  1. azi

    azi Guest

    I have created a file and I'm trying to create a semaphore for it using
    POSIX system calls. My program creates children processes who will open
    the file and write their pid in the file at the same time.

    This is my file:

    void Parent process()

    File *p, *p2;
    p=fopen("file1", "w+");
    if(p==NULL) //error
    else
    fprintf(p,"%u", getpid())
    pclose(p);

    p2=fopen("file2", "w+");
    if(p2==NULL) //error
    else
    fprintf(p2,"%u", getpid())
    pclose(p2);


    void child1(){
    pid=fork();
    if (pid==0)
    //open file1 and write its pid there
    //open file2
    //close file2
    //close file1
    }

    void child1(){
    pid=fork();
    if (pid==0)
    //open file2 and write its pid there
    //open file1
    //close file1
    //close file2
    }

    --
    Posted via http://dbforums.com
     
    azi, Aug 9, 2003
    #1
    1. Advertisements

  2. azi

    Jack Klein Guest

    On Sat, 09 Aug 2003 06:24:42 +0000, azi <>
    wrote in comp.lang.c++:

    >
    > I have created a file and I'm trying to create a semaphore for it using
    > POSIX system calls. My program creates children processes who will open
    > the file and write their pid in the file at the same time.


    [snip]

    Neither POXIS nor semaphores are supported by the C++ language, and
    are off-topic here. Ask this in news:comp.unix.programmer, or perhaps
    a group for your specific *nix flavor, such as
    news:comp.os.linux.development.*

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
     
    Jack Klein, Aug 9, 2003
    #2
    1. Advertisements

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. dede
    Replies:
    0
    Views:
    710
  2. Dima
    Replies:
    0
    Views:
    2,357
  3. Frank Gerlach
    Replies:
    34
    Views:
    15,883
  4. Frank Gerlach

    Really (!) correct Semaphore

    Frank Gerlach, Nov 27, 2004, in forum: Java
    Replies:
    6
    Views:
    557
    Chris Smith
    Nov 28, 2004
  5. Victor Bazarov

    semaphore

    Victor Bazarov, Jul 4, 2003, in forum: C++
    Replies:
    3
    Views:
    977
    chiew peng
    Jul 4, 2003
  6. Bastian Hammer

    Semaphore or what should I use?

    Bastian Hammer, Dec 1, 2004, in forum: Python
    Replies:
    7
    Views:
    2,727
    Pierre Barbier de Reuille
    Dec 6, 2004
  7. techi_C
    Replies:
    2
    Views:
    1,605
    Richard Bos
    Aug 10, 2006
  8. GHUM
    Replies:
    5
    Views:
    877
    Tim Golden
    Aug 29, 2008
Loading...