linux-c-log-rotation-scheme
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void logworker()
{
ino_t inode = 0;
FILE *logfile;
logfile = fopen(logfilename, "a+");
while(running)
{
struct stat mystat;
if (stat(logfilename, &mystat)!=0 || mystat.st_ino != inode)
{
logfile = freopen(logfilename, "a+", logfile);
inode = mystat.st_ino;
}
while (stuff_in_buffer)
{
fwrite(); /* etc */
}
fflush(logfile);
/* sleep until something interesting happens */
}
}
或者 rename
加 freopen
+V why_null 请备注:from博客园