Thread: how to check a file for every 15 mins thr' program

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    28

    Smile how to check a file for every 15 mins thr' program

    hi,
    I am writing a program which is going to be run as deamon process.I want this deamon process to check for a presence of a file placed in one directory for every 15 mins.
    I know how to make a process to run as deamon but not getting idea for checking file for every 15 mins.If it is possible by using alarm() function,how to use it.Can anybody tell me with example to use alarm().
    Also if there is any other way to do,I welcome those ideas.

    Thank You,
    Nitin

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Why not just have sleep(60*15) inside an infinite loop?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Quote Originally Posted by Salem
    Why not just have sleep(60*15) inside an infinite loop?
    sleep takes milliseconds as the argument, thus it should be sleep(60 * 15 * 1000)

    But if he's using linux, he should be using the function usleep, which takes the number of microseconds to wait, thus: usleep(60 * 15 * 1000 * 1000);
    Last edited by hardi; 12-30-2006 at 02:44 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > sleep takes milliseconds as the argument, thus it should be sleep(60 * 15 * 1000)
    This is the Linux board, and POSIX sleep takes seconds.

    Win32 Sleep (note the S), takes milliseconds.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could have a simple script launched by cron every 15 minutes.
    Code:
    #!/bin/sh
    [ -e thefile ] && the_file_exists_deal_with_it
    That would probably be somewhat inefficient though.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    .
    Join Date
    Nov 2003
    Posts
    307
    Recent Linux versions support change notification. Check out inotify, for example.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    28
    Thank You guys for solutions.
    Salem is correct sleep() takes seconds not miliseconds as argument in linux programming.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Posts
    28

    checking presence of file in directory

    I am downloadig file form server to client for every 15 mins trough C my program.So I want to check the file is downloaded or not in specific directory.
    How do I check the presence of the file in specified dirctory in C? So if the file got downloaded then I can proceed to download next file from server.

    Thank You,
    Nitin

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    fopen(file, "r") ?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    Dec 2006
    Posts
    28
    Vart , I am the files I am downloading are media files,so I dont want to open these files.I just wanted to check the presence of the file in directory.Your soulution is also correct ,so that i will get fd of file if it is present.Is there any other way to check presence of file?

  11. #11
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    fopen is nice and easy though, if it fails you don't have the file, if it doesn't the file is present so just close it and call it good.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM