Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is there anyone can tell me how can I write to the same file opened by parent and child?

example:

int main()
{
   pid_t pid ;
   FILE *inp = fopen("test.log","w");

   pid = fork();

   if(pid == 0)
      writeFile(inp);
   else
      writeFile(inp);
}
Posted
Updated 23-Apr-13 21:16pm
v2

1 solution

In priciple you can, but that's 'the recipe to disaster' according to Multiple processes write to the same file (C)[^].
 
Share this answer
 
Comments
[no name] 24-Apr-13 3:52am    
You advice me to use write or fwrite?
CPallini 24-Apr-13 4:00am    
I advice you to NOT write to the same file from the two different processes.
[no name] 24-Apr-13 5:26am    
Can I open two different files for two process?
CPallini 24-Apr-13 6:02am    
Of course.
[no name] 24-Apr-13 9:10am    
Thanks I built a new one..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900