c - 多管道的实现

标签 c linux

我正在编写一个简单的 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/

相关文章:

c - 如何从文本文件中读取单词并添加到字符串数组中?

c++ - 什么是 c c++ 的最佳数据库连接支持库框架?

c - 如何检查 execl() 是否成功(多进程)

c - 在 sigaction 处理程序中使用 flock()

c++ - 在socket编程的select()中重新启动定时器

linux - 摆脱 shell 脚本中的 tail -f

c - C 中有什么方法可以在头文件中转发声明结构而不必在其他文件中使用指针?

linux - 如何获取服务器的点击数

c++ - 编译现有的 C++ 代码以在 DOS 中运行

linux - O_SYNC 写入何时在页面缓存(mmap 文件)中可见?