*nix:“回显‘开始工作’” > /etc/.example” : 这是如何实现的?

发布于 2024-08-28 04:50:17 字数 156 浏览 4 评论 0原文

假设有人在终端中执行以下命令:

echo 'start working' > /etc/.example

执行后,示例程序将“开始工作”。

在 UNIX(类似)系统上,如何实现类似的行为,这种行为被称为什么?

Say someone executes the following in a terminal:

echo 'start working' > /etc/.example

and when this is executed, the example program would "start working."

On UNIX(-like) systems, how would something like that be implemented, and what is this kind of behavior called?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-09-04 04:50:17

有两种一般方法可以做到这一点。

一是正在写入的文件实际上是程序正在读取的命名管道,它会像从任何其他类型的输入流(例如网络套接字或标准输入)接收“开始工作”字符串一样。

另一个(特定于 Linux)是写入的文件是常规文件,并且程序正在使用 inotify(或旧系统上的 dnotify)。当它收到指示文件已更改的 inotify 事件时,它将读取其内容并获取“开始工作”字符串。

请注意,这两种方法都要求相关程序已经在后台运行(并且不执行任何操作)。实际上没有办法以这种方式启动程序,除非有一个后台进程负责启动正在执行上述两件事之一的程序。

There are two general ways to do this.

One is that the file being written to is actually a named pipe that the program is reading from, and it receives the "start working" string as it would from any other sort of input stream (such as a network socket, or standard input).

The other (specific to Linux) is that the file being written to is a regular file, and the program is monitoring the file for changes using inotify (or dnotify on older systems). When it receives an inotify event indicating that the file has changed, it will read its contents and obtain the "start working" string.

Note that both of these methods require that the program in question is already running in the background (and just not doing anything). There is really no way to launch a program in this manner, unless there is for example a background process responsible for launching programs that is doing one of the above two things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文