troubleshooting Question

What is the purpose of "/dev/tty" when using the less command?

Avatar of Maarten Bruins
Maarten Bruins asked on
Unix OSLinuxLinux OS DevShell ScriptingLinux Distributions
47 Comments1 Solution336 ViewsLast Modified:
First I create a regular file with some contents (manual page of find command):

man find > test.txt

Then I use the less command to display some of these contents:

less test.txt

Now I press CTRL-Z to suspend the process. The process is still open, so now I can execute this command:

lsof | grep 'less'

By doing this, I get an idea which files are open with respect to the less-process. My result:

COMMAND  PID    USER  FD   TYPE  DEVICE  SIZE/OFF  NODE       NAME
less     24565  root  cwd  DIR   0,38    4096      21473055   /
less     24565  root  rtd  DIR   0,38    4096      21473055   /
less     24565  root  txt  REG   0,38    149944    22143102   /usr/bin/less
less     24565  root  mem  REG   9,1               22143102   /usr/bin/less (path dev=0,38)
less     24565  root  mem  REG   9,1               22135172   /usr/lib/locale/locale-archive-rpm (path dev=0,38)
less     24565  root  mem  REG   9,1               21741879   /lib64/libc-2.12.so (path dev=0,38)
less     24565  root  mem  REG   9,1               22265955   /usr/local/lib/libpcre.so.0.0.1 (path dev=0,38)
less     24565  root  mem  REG   9,1               21741743   /lib64/libtinfo.so.5.7 (path dev=0,38)
less     24565  root  mem  REG   9,1               21741946   /lib64/ld-2.12.so (path dev=0,38)
less     24565  root  0u   CHR   136,1   0t0       4          /dev/pts/1
less     24565  root  1u   CHR   136,1   0t0       4          /dev/pts/1
less     24565  root  2u   CHR   136,1   0t0       4          /dev/pts/1
less     24565  root  3r   CHR   5,0     0t0       207524942  [b]/dev/tty[/b]
less     24565  root  4r   REG   0,38    82765     25520978   /test.txt

The "/dev/tty" is the "controlling terminal" for the current process. The child process (less) inherits the terminal of the parent process (bash). Then why they are not just showing "/dev/pts/1" in this case (instead of "/dev/tty")?
ASKER CERTIFIED SOLUTION
nociSoftware Engineer
Join our community to see this answer!
Unlock 1 Answer and 47 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 47 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros