Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 654875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:32:31+00:00 2026-05-13T22:32:31+00:00

I wrote a small program, that creates files at an interval of 1 minute.

  • 0

I wrote a small program, that creates files at an interval of 1 minute. But the time at which the file is created and last written and the last modification time of the file as shown by ls command differs by 1 second. The code and the output is presented below. please let me know where could be the bug?

root@new:/home/srinivas# cat b.c
#include <time.h>
#include <stdio.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
int main ()
{
    int fd;
    int i=0;
    time_t initial_time = time(NULL);
    time_t interval = 60;
    time_t curr_time = time(NULL);

    fd=open ("test1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    write(fd,"abcd1",5);
    while(1)
    {
        curr_time = time(NULL);
        if(curr_time >= initial_time)
        {
            if(i==0)
            {
                close(fd);
                printf("\ntime before test2.txt fileopen= %d\n", time(NULL));
                fd=open ("test2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
                write(fd,"abcd2",5);
                printf("time after test2.txt filewrite= %d\n", time(NULL));
                system("ls -l --time-style=+%s test2.txt");
                initial_time += interval;
                i=1;
            }
            else
            {
                close(fd);
                printf("\ntime before test1.txt fileopen= %d\n", time(NULL));
                fd=open ("test1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
                write(fd,"abcd1",5);
                printf("time after test1.txt filewrite= %d\n", time(NULL));
                system("ls -l --time-style=+%s test1.txt");
                initial_time += interval;
                i=0;
            }
        }
        usleep(1000);
    }
    return 0;
}
root@new:/home/srinivas# gcc b.c
root@new:/home/srinivas# ./a.out

time before test2.txt fileopen= 1268203133
time after test2.txt filewrite= 1268203133
-rw-r--r-- 1 root root 5 1268203133 test2.txt

time before test1.txt fileopen= 1268203193
time after test1.txt filewrite= 1268203193
-rw-r--r-- 1 root root 5 1268203192 test1.txt

time before test2.txt fileopen= 1268203253
time after test2.txt filewrite= 1268203253
-rw-r--r-- 1 root root 5 1268203252 test2.txt

time before test1.txt fileopen= 1268203313
time after test1.txt filewrite= 1268203313
-rw-r--r-- 1 root root 5 1268203312 test1.txt

time before test2.txt fileopen= 1268203373
time after test2.txt filewrite= 1268203373
-rw-r--r-- 1 root root 5 1268203372 test2.txt

root@new:/home/srinivas# ls -ltr --time-style=+%s
total 40
-rwxrwxrwx  1 root     root      1095 1268202457 b.c
-rwxr-xr-x  1 root     root     10300 1268202459 a.out
-rw-r--r--  1 root     root         5 1268203312 test1.txt
-rw-r--r--  1 root     root         5 1268203372 test2.txt
root@new:/home/srinivas#

Thanks and regards,

Srinivas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:32:32+00:00Added an answer on May 13, 2026 at 10:32 pm

    http://www.spinics.net/lists/kernel/msg1008110.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that creates a small file in the Bin directory for
I want to write a small program that should print something like testing CPU...
I need to write a small program that can detect that it has been
I would like to write a small program in C# which goes through my
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I wrote a small PHP application that I'd like to distribute. I'm looking for
We wrote a small Windows class library that implements extension methods for some standard
I wrote this small program today and I was blown away by the results.
I've written a small CUDA program on my macbook pro and now tried it
I want to write a small program in .NET 4.0 that will open a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.