1

如何printf在 Minix 3.2.1 上写入当前时间?
我尝试gmtime像下面这样使用,但它在time(&nowtime).

#include <sys/time.h>
#include <time.h>

struct tm *now;
time_t nowtime;
time(&nowtime);
now=gmtime(&nowtime);

printf("TIME is NOW %s",now);

此外,我尝试在内核(/usr/src/kernel/main.c)中回忆这一点,因为我需要在 minix 启动时说明内核进程何时完成并切换到用户。

我在上面的代码中遇到了一些错误,比如在重建内核时,如下所示;

在此处输入图像描述

4

1 回答 1

0

对 minix 不太熟悉,但它类似于 Unix 和 Linux,所以也许该平台上的某些东西可能会出现在 minix 上……所以有几种方法

  • 跑一个人ctime

  • Linux 命令的手册页time()包含此示例代码(您可能必须针对 minix 进行修改,但它显示了如何使用asctime() localtime() and time()):

      #include <stdio.h>
      #include <time.h>
    
      int main(void)
      {
          time_t result;
    
          result = time(NULL);
          printf("%s%ju secs since the Epoch\n",
              asctime(localtime(&result)),
                  (uintmax_t)result);
          return(0);
      }
    
于 2014-11-16T05:43:10.650 回答