假设我开始一个流程:
#!/usr/bin/env bash
while read line; do
echo "stdin message: $line"
done < "/dev/stdin"
显然这个过程正在监听要写入其标准输入的数据。另一个进程如何写入它?
这取决于进程的stdin
连接到什么。如果它是命名管道,则它们写入管道文件。如果它是伪tty,则它们写入相应的主设备。
在大多数其他情况下,通常不可能。
使用Linux:在while循环之前添加:
echo $$
在另一个shell中,使用PID(例如12345),如下所示:
echo "hello" >/proc/12345/fd/1