写入进程侦听消息的stdin

问题描述 投票:1回答:2

假设我开始一个流程:

#!/usr/bin/env bash

while read line; do
 echo "stdin message: $line"
done < "/dev/stdin"

显然这个过程正在监听要写入其标准输入的数据。另一个进程如何写入它?

bash shell ipc stdin file-descriptor
2个回答
1
投票

这取决于进程的stdin连接到什么。如果它是命名管道,则它们写入管道文件。如果它是伪tty,则它们写入相应的主设备。

在大多数其他情况下,通常不可能。


1
投票

使用Linux:在while循环之前添加:

echo $$

在另一个shell中,使用PID(例如12345),如下所示:

echo "hello" >/proc/12345/fd/1
© www.soinside.com 2019 - 2024. All rights reserved.