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