开发者

*nix: "echo 'start working' > /etc/.example" : how is this implemented?

Say someone executes the following in a terminal:

echo 'start working' > /et开发者_如何学Pythonc/.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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜