From: Oasjxzcoijoasjdflas Asdfizxcv kklas Date: 2009-05-14T01:09:27+09:00 Subject: Re: How Check File Busy? Greg Willits wrote: > Hey everyone, thanks for the input. > > My FTP server does indeed support post processing. Should have thought > of that. However, I'd rather not couple this particular process to the > FTP server if possible. > > I read up on fuser and lsof, and will experiment with those options > first. > > I have some options now, so thanks. > > -- gw You can "easy" write a small C snipplet that checks if something happens to a file and then make a ruby-class of this and use it in your ruby program. Here is a sketch... ------ #include #include #include #include #include #define TMOUT_SEC 2 #define TMOUT_NSEC 0 //********************************************************************** // This handles events. It blocks on kqueue. //********************************************************************** handle_events(int kq ) { const struct kevent ch; struct kevent ev; int nchanges; int nevents; int error; int i; int n; struct timespec timeout = { TMOUT_SEC, TMOUT_NSEC }; n = kevent(kq, &ch , nchanges, &ev, nevents, &timeout ); if( n <= 0 ) { perror(error); /* what kind of error */ exit(-1); } for( i = 0 ; i < n; i++ ) { if(ev[i].flag & EV_ERROR) exit(-1); /* error */ if(ev[i].filter == EVFILT_READ) readable_fd(ev[i].ident); if(ev[i].filter == EVFILT_WRITE) writable_fd(ev[i].ident); } } readable_fd( int fd ) { printf("File_fd to read %d\n", fd ); } writable_fd( int fd ) { printf("File_fd to read %d\n", fd ); } update_fd(int fd, int action, int filter ) { ch[nchanges].ident = fd; ch[nchanges].filger = filter; ch[nchanges].flags = action == ADD ? EV_ADD : EV_DELETE; nchanges++; } main() { int kq; kq = kqueue(); printf("Start of program\n"); handel_events( kq ); } And then you need to make it to a ruby class. Read in the ruby book how to do this... ------ #include "ruby.h" #include static int id_push; static VALUE t_init( VALUE self ) { ... } static VALUE t_notify( VALUE self, VALUE obj ) { ... } VALUE cTEST; void Init_my_test(){ cTEST = rb_define_class("myTest", rb_cObject); rb_define_method( cTest, "initialize", t_init, 0); rb_define_method( cTest, "notify", t_notify, 1); id_push = rb_intern("push"); } Then compile and use ------ require 'my_test' t = MyTest.new # look for close or write or name change... while... t.notify("filename"); -- Posted via http://www.ruby-forum.com/.