Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: How can we know whether a file is read or not #3611
    Chandra3993
    Participant

    Straight way you can not check the file is read or not.
    For specific number of days or epoch seconds you can check

    Here I have written the program for checking file is read in last 2 days


    #include
    #include
    #include
    #include
    #include

    main()
    {
    struct stat but ;
    // Here you need to give the file name with absolute path.
    stat("/home/pavunkumar/secrect",&but );
    // Here I have calculated the one day epoch time.
    int limit = 24*60*60;
    // Getting the last read time of the file.
    int read = but.st_atime ;
    int current ;
    // Getting the current epoch time.
    current=time ( NULL ) ;
    // Check file is not open for 2 days.
    if (((current-read)/limit) >= 2 )
    {
    printf ( "file is not read ");
    }
    else
    {
    printf ( "file is read " ) ;
    }
    }

    in reply to: C program timeout #3626
    Chandra3993
    Participant

    You use can sleep function for prompting to require amount of time.

    In condition you add the sleep(10).

    It will wait for 10 seconds, then do the require stuffs

Viewing 2 posts - 1 through 2 (of 2 total)