LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2004, 03:45 AM   #1
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
Problem with asynchronous notification


I am trying to write a program which checks whether a file is modified or not. if it is modified it must exit. I have written the following code. but the program is not exiting even though i modified the file. i am using f_notify of fcntl to receive notfification.

#define _GNU_SOURCE
#include<unistd.h>
#include<fcntl.h>
#include <stdio.h>
#include <signal.h>

main()
{

int fd;
int sig_hand();
signal(SIGIO,sig_hand);
fd = open("/root/br.xml", O_RDONLY);
fcntl(fd,F_SETOWN,getpid());
fcntl(fd,F_SETFL,FASYNC);
fcntl(fd, F_NOTIFY, DN_MODIFY);

for(;{
printf("Here i am waiting for the file to be changed\n");

}

}
int sig_hand()
{
printf("File is changed, i m exiting ");
exit(0);
}

any help plz
rajesh
 
Old 09-17-2004, 05:10 AM   #2
Sadrul
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware 10.0 (K: 2.4.26)
Posts: 13

Rep: Reputation: 0
from the man-page of `fcntl':
Code:
       F_NOTIFY
              (Linux  2.4  onwards)  Provide  notification  when  the directory
              referred to by fd or  any  of  the  files  that  it  contains  is
              changed.
so you have to open the dir rather than the file itself.

-- Adil
 
Old 09-17-2004, 07:58 AM   #3
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Original Poster
Rep: Reputation: 15
thankx for u r advice.
Is there any way to find out whether a file has been modified or not and getting that notificatoin asynchronously.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming asynchronous I/O in Linux with C iuaui Programming 2 09-30-2005 05:01 PM
problem with email notification of new posts titanium_geek LQ Suggestions & Feedback 6 06-15-2005 04:14 PM
running asynchronous jobs Raptor Ramjet Linux - General 3 12-01-2004 02:49 AM
Synchronous vs Asynchronous Transfers WeNdeL Linux - Hardware 0 10-22-2003 03:34 PM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration