r/ProgrammerTIL • u/cdrini • Sep 14 '21
Other Language [Unix] TIL root can write to any process' stdout
Start a long running process:
tail -fIn another shell:
# Get the process' ID (Assuming you only have one tail running)
TAIL_PID=$(pgrep tail)
# Send data to it
echo 'hi' > /proc/$TAIL_PID/fd/1Observe the first shell outputs "hi" O.O Can also write to stderr. Maybe stdin?
121
Upvotes
View all comments
21
u/HugoNikanor Sep 14 '21
It's not limited to root. Also, it's just that a process gets its controlling terminal as STDOUT (and STDERR and STDIN). For example: