PDA

View Full Version : how to check a file for every 15 mins thr' program



nitinmhetre
12-30-2006, 06:47 AM
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

Salem
12-30-2006, 06:53 AM
Why not just have sleep(60*15) inside an infinite loop?

hardi
12-30-2006, 02:42 PM
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);

Salem
12-30-2006, 05:11 PM
> 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.

dwks
12-30-2006, 05:19 PM
You could have a simple script launched by cron every 15 minutes.


#!/bin/sh
[ -e thefile ] && the_file_exists_deal_with_it

That would probably be somewhat inefficient though.

jim mcnamara
12-30-2006, 08:20 PM
Recent Linux versions support change notification. Check out inotify, for example.

nitinmhetre
01-03-2007, 03:40 AM
Thank You guys for solutions.
Salem is correct sleep() takes seconds not miliseconds as argument in linux programming.

nitinmhetre
01-05-2007, 01:13 AM
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

vart
01-05-2007, 01:28 AM
fopen(file, "r") ?

nitinmhetre
01-05-2007, 01:42 AM
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?

Wraithan
01-05-2007, 01:53 AM
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.