如何在Linux上strftime()中避免过多的stat(/ etc / localtime)调用?

我留下了一个logging下的处理程序,让我在几分钟之内运行。

这显示在这些分钟超过200 000 000调用stat("/etc/localtime",..)这听起来有点过分和不必要的。

strace输出如下所示:

 write(1, "C137015 393393093052629137110 47"..., 16384) = 16384 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2225, ...}) = 0 read(0, "\224q\1\207\0\0\202\1\4\203\1\4\204\1\1\205\1\1\206\1\7\207\1\6\211\1\22\212\1\22\213\1"..., 16384) = 16384 

基本上,事实certificate,每个logging处理1 stat()调用,罪魁祸首竟然是这个相当普通的代码行

 strftime(call->date_time,DATELEN,"%Y%m%d %H%M%S",&tm_buf); 

所以 – 我怎样才能避免在每次调用strftime()调用stat(/ etc / localtime)?

Solutions Collecting From Web of "如何在Linux上strftime()中避免过多的stat(/ etc / localtime)调用?"

这可能是因为你的时区没有设置。 strftime查询/etc/localtime来找到它。

尝试设置TZ环境变量。

这是该行为的链接 。