简体   繁体   English

使用C语言中的Unix概念的目录监视器代码

[英]Code for directory monitor using Unix concepts in C language

On a server, a process monitors the files in a Unix file system. 在服务器上,进程监视Unix文件系统中的文件。

If a client sends the file name to be monitored, the server has to send the report to the client whether that file got changed or deleted. 如果客户端发送了要监视的文件名,则服务器必须将报告发送给客户端,无论该文件已更改还是删除。

For server-client communication, we should use either message queues or sockets. 对于服务器-客户端通信,我们应该使用消息队列或套接字。

For every change in the file, the server has to notify that change. 对于文件中的每个更改,服务器都必须通知该更改。

For all changes in all files, the server has to maintain one logfile so that user can view it through the command line interface. 对于所有文件中的所有更改,服务器必须维护一个日志文件,以便用户可以通过命令行界面查看它。

Server could use two threads: one for communication, the other for monitoring. 服务器可以使用两个线程:一个用于通信,另一个用于监视。

How can you do this efficiently? 您如何有效地做到这一点?

Have a look at inotify at http://en.wikipedia.org/wiki/Inotify - linux only I'm afraid. http://en.wikipedia.org/wiki/Inotify上查看inotify-恐怕只有Linux。

BSD has kqueue - see http://en.wikipedia.org/wiki/Kqueue . BSD具有kqueue-请参见http://en.wikipedia.org/wiki/Kqueue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM