If I do this:
x | y
is there any way to check, during the runtime of x, to see if it's connected to y? Note that I don't know what y is, and I am not responsible for starting y.
Specifically, I am talking about the Node.js runtime, so perhaps this is a Node.js specific question. But ultimately, I am wondering if it's possible to determine given any runtime. Is it possible and how?
Is it possible to determine if the stdout/stderr are hooked up to the stdin of another process? I guess that's what this question is about.
/proc/<pid-x>/fd/1
and/proc/<pid-y>/fd/0
would be links to the same pipe. – muru Jul 31 '17 at 04:30/proc/*/fd/0
(on Linux, again). For example, I usedfind
andawk
for that: https://unix.stackexchange.com/a/156152/70524 – muru Jul 31 '17 at 04:39lsof
should show processes that have the file opened as well – EkriirkE Jul 31 '17 at 05:20