- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: how to get file date/time of creation or updat...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2007 10:56 PM
06-27-2007 10:56 PM
i have this daemon that must read this config xml file, but when this xml file changes the daemon must detect this and perform a new read.
how can i do this ?
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2007 11:08 PM
06-27-2007 11:08 PM
SolutionSIGHUP is commonly taken because daemons have no real use for this signal anymore as they have dissociated from any controlling terminal and have either redirected or reopened their standard file descriptors stdin, stdout and stderr.
- Tags:
- SIGHUP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2007 11:08 PM
06-27-2007 11:08 PM
Re: how to get file date/time of creation or update
SIGHUP is commonly taken because daemons have no real use for this signal anymore as they have dissociated from any controlling terminal and have either closed or reopened their standard file descriptors stdin, stdout and stderr.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2007 11:11 PM
06-27-2007 11:11 PM
Re: how to get file date/time of creation or update
the ITRC webserver is slow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2007 11:39 PM
06-27-2007 11:39 PM
Re: how to get file date/time of creation or update
Ralph has provided the standard approach.
If you feel that you must be intrinsically sensitive to changes in the configuration file, your daemon could periodically 'stat()' the configuration file for its 'mtime'. At startup you would have cached the file's value. If the 'mtime' has changed, reread the configuration and re-cache the new timestamp. A 'sigalam' could be useful to construct the appropriate behavior.
Regards!
...JRF...
- Tags:
- stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 12:16 AM
06-28-2007 12:16 AM
Re: how to get file date/time of creation or update
By the way, Unix has no such thing as a "creation" timestamp. The 'mtime' (last modification time) [see 'stat(2)'] happens to equate to a creation point only when a file is first created. Subsequent modifications of the file's contents obliterate the original timestamp value.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 06:49 PM
06-28-2007 06:49 PM
Re: how to get file date/time of creation or update
but i am still trying to do this in the standard way with the signal signal(SIGHUP,mostrasinal); anyone knows where i can get an example of a daemon with configuration files.
thanks
///buscar o mtime do ficheiro
time_t buscafichmtime(const char *filename)
{
struct stat sbuf;
if(stat(filename,&sbuf) == -1)
{
perror("stat");
exit(1);
}
return sbuf.st_mtime;
}
main()
/* Daemonize */
daemonize( DAEMON_NAME );
time_init=buscafichmtime(CONFIG_FILE_NAME);
time_temp = 0;
while(1)
{
time_actual=buscafichmtime(CONFIG_FILE_NAME);
cout << "time_actual : " << time_actual << endl;
if (time_temp==0)
{
if(time_actual!=time_init)
{
cout << "time_actual!=time_init"<
}
time_temp=time_actual;
}
else
{
if(time_actual!=time_temp)
{
cout << "time_actual!=time_temp"<
}
time_temp=time_actual;
}
cout << "mtime init :" << time_init << endl;
sleep(1); /*run*/
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 07:02 PM
06-28-2007 07:02 PM
Re: how to get file date/time of creation or update
signal(SIGHUP,mostrasinal);
What problems are you having? In your signal handler mostrasinal, you just set a volatile flag indicating you need to reread your config files.
Then in your main while loop, you test it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 09:55 PM
06-28-2007 09:55 PM
Re: how to get file date/time of creation or update
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 10:06 PM
06-28-2007 10:06 PM
Re: how to get file date/time of creation or update
Ah, I thought the suggestion was that you were going to require them to send SIGHUP?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2007 11:53 PM
06-28-2007 11:53 PM
Re: how to get file date/time of creation or update
A couple of comments.
> the problem is when someone changes the config.xml file the signal is not called, only with stat i can verify if the file was changed
You need to have a signal handler that catches the SIGHUP signal (when it is sent) and calls a function whose purpose is to re-read your configuration file.
As Ralph noted, this is a standard paradigm for handling a daemon's configuration file and the need to re-read it without terminating and restarting the daemon. It gives *you* control over *when* you want to re-read a modified configuration file.
My suggestion to use SIGALRM was based on the idea that you could do something like the following. In the normal life of your daemon, events happen to awaken it perform its intended work. Perhaps as a you finish a cycle of that work you also call a function that stat()'s the configuration file to see if it has changed and re-read it if so.
Also as a part of the normal work cycle, you raise your own SIGALRM to schedule a "wake-up" in some reasonable number of seconds (maybe every minute). A signal handler also exists for SIGALRM and if invoked, it calls your fucntion to stat()' the configurtion file. The idea is that if no other event awakens your daemon, your alarm does and thus you remain sensitive to configuration file changes. Cancel the SIGALRM any time yo had real work and have otherwise interrogated the configuration file.
By the way, in the code you posted, you poll every second. This will make your code very processor intensive without any real gain. After all, the granularity of stat() timestamps is only one-second anyway. Perhaps you have the setting so low only for testing your code.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2007 11:15 PM
07-01-2007 11:15 PM
Re: how to get file date/time of creation or update
i am doing sleep(1) to test.
The problem is that when someone changes the configuration file , the daemon it is not getting any event.
the only solution i have this moment thanks to you is to stat() the configuration file.
i am now looking for a way to monitor the configuration file.
the sleep cannot be larger the 1 minute , if someone changes the configuration file and the daemon is not updating the memory segment that someone is going to be very unhappy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2007 11:46 PM
07-01-2007 11:46 PM
Re: how to get file date/time of creation or update
can i find something like this in HP-UX ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2007 11:53 PM
07-01-2007 11:53 PM
Re: how to get file date/time of creation or update
That's why you put the burden on the end user to send that SIGHUP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2007 12:37 AM
07-02-2007 12:37 AM
Re: how to get file date/time of creation or update
> Linux has something called FAM...can i find something like this in HP-UX ?
I don't think so. Based on the documentation, I think you understand your options. Once agan, the SIGHUP method is a standard one. Perhaps most importantly, using SIGHUP gives *you* control as to when you want your daemon to "see" a changed configuration.
I found a seemingly good overview of the FAM product here:
http://oss.sgi.com/projects/fam/faq.html
Regards!
...JRF...