By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,572 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

How to create a semaphore for a file

P: n/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
}

--
Posted via http://dbforums.com
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 09 Aug 2003 06:24:42 +0000, azi <me*********@dbforums.com>
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.