RSS Feed

Comments RSS

The Watch Folder

For the programmers and systems administrators among us.  Consider the following, and all too common, programming task. Events from one process need to trigger actions by another.  Now, the impulse may be to try to impliment a direct method of communications between the two process via networking sockets, low level OS signals, etc.  While this may be good to consider or even use at times, there may be a far more simple and less problematic method that is almost always worth considering – the Watch Folder.    If both processes can have access to a common directory, via network share or direct filesystem mount for instance, then all one has to do is have the first process drop a small file to the locaton and have the other process be watching for it, act in response and then clear it out and wait again for the next time the file appears in order to act again.   The second process can watch for it directly or have some other task be the watcher that then calls the final process, perhaps through a periodic call from a task scheduler such a cron.   There are lots of realitively simple ways of implementing such an arrangement without resorting to more complex networking or OS signaling programming schemes.   The Watch Folder methodology works well in any language but is particularly easy to implement in simple scripting languages that are available as part of the command shell of most any OS, such as BASH in Linux, Bourne or Korn Shell in Unix, or DOS Batch or Powershell script in Windows.