command < file is used to redirect content from a file into a command.
On virtual terminal 1 (/dev/tty1), I run
less < file. Then on another virtual terminal, I run
lsof -p <pid of the less process> and see the (trimmed) output:
FD name ---------------- 0r /root/file 1u /dev/tty1 2u /dev/tty1 3r /dev/tty
I interpret this as:
- stdin is /root/file. The process can only read from /root/file.
- stdout is /dev/tty1. The process can read from and write to /dev/tty1 (though I don't know why the process needs to read from its own output...)
- stderr is /dev/tty1. The process can read from and write to /dev/tty1 (again, why does the process needs the permission to read from the error logs that it outputs?)
- The last line is a non-standard stream. I don't know what it is for, but the process can only read from it.
Even though the
stdin is /root/file, I can still interact with the
less process (ex. typing '/' to enter search mode and search for a word). This means the process still accepts input from the current virtual terinal (/dev/tty1). I thought that since the
stdin is not /dev/tty1, I should not be able to interact with the
less process via typing on the keyboard?