23,216
社区成员




#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
pid_t child_pid = fork ();
if (child_pid != 0)
{
printf ("child_pid = %d\n", child_pid);
_exit (0);
}
FILE *stream = fopen ("/tmp/test.txt", "w");
if (stream == NULL)
{
return -1;
}
time_t last_rawtime = 0;
while (1)
{
usleep (100000);
time_t rawtime = time (NULL);
if (last_rawtime == rawtime)
{
continue;
}
last_rawtime = rawtime;
struct tm timeinfo = { 0 };
localtime_r (&rawtime, &timeinfo);
fprintf (stream, "%02u:%02u:%02u\n",
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
fflush (stream);
printf ("%02u:%02u:%02u\n",
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
for (int i = 0; i < 24; i++)
{
printf (
"---------------- "
"---------------- "
"---------------- "
"---------------- "
"---------------- "
"---------------- "
"----------------\n");
}
}
return 0;
}