|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
File Creation notification
Hello,
Please help about writing a process that will be automatically notified by file creation in a predefined directory. Some code will appreciated. Thanks for all. |
| Sponsored Links | ||
|
|
|
|||
|
The brute force methods will work, but many systems today provide better ways to watch for file changes. I've listed some ideas at Monitoring file or directory changes
|
|
|||
|
Hello and thank you for these answers.
To clarify a little more the subject, the problem isn't to write a program which wakes up every n seconds to analyze if there is something under a directory. But to make a subscription to be notified by an event and to fall asleep until the arrival of the asynchronous event like "FILE ADDED". |
|
||||
|
Are you talking about writing a program to monitor a FIFO pipe so the program will sleep untill another program activates the pipe then the first program will wake up and do it's bit ? Here's a small C section to do that Code:
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(void)
{
FILE* fp;
time_t t;
const char * file = "my_fifo_fil";
if (mkfifo(file, 0644) == -1)
{
printf("Error initializing fifo %s\n", file);
return -1;
}
if(!(fp = fopen(file, "w")))
{
printf("Error opening fifo %s\n", file);
return -1;
}
t = time(NULL);
if(fprintf(fp,"Program Woken at: %s\n", ctime(&t)) < 0)
{
printf("Error printing to fifo %s\n", file);
return -1;
}
printf("You woke me poking my fifo %s\n", file);
if(close(fp) == -1)
{
printf("Error closing fifo %s\n", file);
return -1;
}
if(unlink(file) == -1)
{
printf("Error unlinking fifo %s\n", file);
return -1;
}
return 0;
}It is used from one terminal as: Quote:
Last edited by redhead; 11-10-2009 at 12:39 PM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| filenotification, signal |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gzip a file and append creation date stamp to file | jacktravine | Solaris | 3 | 09-22-2009 11:09 AM |
| file generation and mail notification | anzie.sharma | Shell Programming and Scripting | 4 | 08-26-2008 05:58 AM |
| mail notification on file generation | anzie.sharma | UNIX for Dummies Questions & Answers | 2 | 08-25-2008 09:34 AM |
| FTP and LOg file creation | agarwalniru | Shell Programming and Scripting | 2 | 03-12-2008 11:10 AM |
| csv file creation | Student37 | UNIX for Dummies Questions & Answers | 2 | 02-25-2006 02:38 PM |