[英]how to generate a signal when a Data is written into file?
When ever C program exectues it produces error or executes sucessfully. 每当C程序执行时,它都会产生错误或成功执行。 If it produces error I am redirecting the error to a file error.log.
如果产生错误,我会将错误重定向到文件error.log。 I want a Signal (notification) to be generated as soon as a write action takes place on error.log, this signal should invoke another program say, Parser.c which will read the error.log copy into buffer and clear the contents of log file.
我希望在error.log上执行写操作后立即生成一个Signal(通知),该信号应调用另一个程序Parser.c,该程序将把error.log副本读入缓冲区并清除log的内容文件。
Is it possible that a file generates a signal to invoke another program if yes then how can we achieve it programmatically? 如果是,文件是否可能生成信号来调用另一个程序,那么我们如何以编程方式实现它?
I believe the answer will be different on different systems. 我相信答案在不同的系统上会有所不同。 I would suggest that you just start that other program from the first program (fork a new process on Linux) after you are done writing on file.
我建议您在完成文件写入后,从第一个程序(在Linux上需要一个新的过程)中启动另一个程序。
One way would be to use the asynchronous I/O mechanism (aio_*), these will send a signal as specified in the AIO control block (check the man page for further details, it's pretty complete). 一种方法是使用异步I / O机制(aio_ *),它们将发送AIO控制块中指定的信号(有关更多详细信息,请参见手册页,它非常完整)。 Essentially you would be setting up an AIO control block for reading, and issue an aio_read().
本质上,您将设置一个用于读取的AIO控制块,然后发出aio_read()。 When the signal is received, you would process the data.
收到信号后,您将处理数据。 aio(7) for Linux is a pretty useful man page regarding this.
关于Linux的aio(7)是一个非常有用的手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.