How to create a semaphore for a file

A

azi

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
}
 
J

Jack Klein

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 or perhaps
a group for your specific *nix flavor, such as

--
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top