gpt4 book ai didi

c - 多管道的实现

转载 作者:行者123 更新时间:2023-11-30 17:10:49 25 4
gpt4 key购买 nike

我正在编写一个简单的 shell,我想实现一个管道。

那么,让我们考虑一下:

<command1> | <command2> | <command3> | ...

现在,我的想法是:

启动command1并等待他的pid。然后运行command2并等待他。等等。

  1. 这是个好主意吗?

  2. 如何实现:

    <command1> | <command2> | <command3> &

最佳答案

Now, my idea is:

Start command1 and waitpid for him. Then run command2 and waitpid for him. And so on.

Is it a good idea?

没有。也许开始阅读pipe(2) 。进程必须同时运行才能通过管道进行通信。 (并且您想要为此使用实际管道,而不是一些临时存储)。

关于c - 多管道的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32698736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com