How to create a semaphore for a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • azi

    How to create a semaphore for a file


    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
  • Jack Klein

    #2
    Re: How to create a semaphore for a file

    On Sat, 09 Aug 2003 06:24:42 +0000, azi <member34294@db forums.com>
    wrote in comp.lang.c++:
    [color=blue]
    >
    > 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.[/color]

    [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.li nux.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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

    Comment

    Working...