fork(),fopen()子和父写同一个文件? [英] fork() , fopen() child and parent write the same file?
本文介绍了fork(),fopen()子和父写同一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人可以告诉我如何写入父母和孩子打开的同一个文件?
例如:
int main()
{
pid_t pid;
FILE * inp = fopen(test.log,w);
pid = fork();
if(pid == 0)
writeFile(inp);
else
writeFile(inp);
}
解决方案
原则上你可以,但那是灾难的秘诀,根据< a href =http://stackoverflow.com/questions/12300676/multiple-processes-write-to-the-same-file-c>多个进程写入同一个文件(C) [ ^ ]。
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); }
解决方案
In priciple you can, but that''s ''the recipe to disaster'' according to Multiple processes write to the same file (C)[^].
这篇关于fork(),fopen()子和父写同一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文