我有两个(POSIX)线程,像这样写入日志文件:
pthread_mutex_lock(&log_mutex);
fprintf(LOG, "something...\n");
fsync(fileno(LOG));
pthread_mutex_unlock(&log_mutex);
文件在 main()
中以模式 "a" 使用 fopen()
打开。在进程运行时,我无法使用 cat
或 tail
查看文件中的任何内容,但是在进程终止并关闭文件(使用fclose()
)后,所有行都存在其中。
我做错了什么?