Windows 和 Linux 中的管道有什么区别?

发布于 2024-07-06 16:22:35 字数 33 浏览 6 评论 0原文

Windows 和 Linux 中的管道有什么区别?

What are the differences between pipes in Windows and Linux?

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

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

发布评论

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

评论(4

三生一梦 2024-07-13 16:22:35

我知道的一个区别是,Linux 下的命名管道是文件系统中的实际条目(您将在目录列表中看到它,它们有一种特殊类型),而在 Windows 上,它们存储在某个神奇的存储库中(它们都是通过路径“\\.\pipe\”访问的。

其次,在 Linux 中,您可以使用标准文件 IO 方法从管道中写入/读取它们。特殊的“管道”函数是 Win32 API 的一部分,

我更喜欢 Linux 的方法,因为它可以让我在任何我想要的应用程序中使用管道,例如:

mkfifo pipe.wav
decodeMP3 song.mp3 --out pipe.wav &
encodeAVI video.mpeg pipe.wav --out video.avi

这可以让我将 MP3 解码器的输出直接通过管道传输到视频解码器中。必须首先将整个 MP3 解码为磁盘上的 WAV 文件 如果您有双核 CPU,这会很方便,因为这样您就可以同时运行这两个操作,从而获得很好的加速。

One difference that I know of, is that named pipes under Linux are actual entries in the filesystem (you'll see it in a directory listing, they have a special type), whereas on Windows they are stored in some magical repository somewhere (they are all accessed via the path "\\.\pipe\".

Secondly, in Linux you can just write/read from pipes as if they were any other file, using standard file IO methods. Whereas on windows, you have to use the special 'Pipe' functions which are part of the Win32 API.

I like linux's method better, because it lets me use pipes with any app I want. Eg:

mkfifo pipe.wav
decodeMP3 song.mp3 --out pipe.wav &
encodeAVI video.mpeg pipe.wav --out video.avi

This lets me pipe the output of the MP3 decoder directly into the video decoder, instead of having to first decode the entire MP3 into a WAV file on disk. It's handy if you have a dual-core CPU, because then you are running both operations at once, for a nice speedup.

池予 2024-07-13 16:22:35

另一个重要的区别

在windows下

A | B | C 

直到A完成其输出B才开始读取,对于C读取B输出也是如此

*nix将输入和输出挂钩在一起,以便C可以读取B的输出,B可以读取A的输出,而A和 B 仍在运行

吞吐量大致相同,但使用 *nix 时输出显示得更快。

Another important difference

Under windows

A | B | C 

Until A is done with it's output B does not start reading, The same for B output being read by C

*nix hooks the input and output together so that C can read B's output and B can read A's output while A and B are still running

The throughput is about the same but output shows up faster with *nix.

秋叶绚丽 2024-07-13 16:22:35

在 Linux(以及一般的 *ix)下,“一切都是文件”。 您可以不受限制地读/写/查找管道、套接字和设备,只要这些操作有意义。

而 Windows 对于这些不同类型的对象的体系结构远不那么统一。 虽然我无法告诉您详细信息,但我知道 Windows 和 Linux 之间的管道缓冲有很大不同,因此您可能会遇到困难。

此外,管道的一种常见 Unix-y 使用是 fork() 一个子进程,然后通过管道与其通信(父进程打开一端,子进程打开另一端)。 在 Windows 下,这种事情是不可能的。 IPC 机制有很大不同。

Under Linux (and *ix in general), "everything is a file". You can read/write/seek pipes and sockets and devices with no restrictions, insofar as those operations make sense.

Whereas Windows has a far less unified architecture for these different types of objects. Though I couldn't tell you the details, I know that buffering of pipes is considerably different between Windows and Linux, so you may run into difficulties there.

Also, one common Unix-y use of pipes is to fork() a subprocess and then communicate with it via a pipe (the parent opens one end, the child opens the other end). Under Windows, that kind of thing just isn't possible. IPC mechanisms are quite different.

妞丶爷亲个 2024-07-13 16:22:35

另请参阅上一个线程:

什么是命名管道?

其中包含我的看法和其他几个人们'

See also the previous thread:

What are named pipes?

Which contains my take and several other peoples'

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