Search code examples
linuxbashfile-descriptorlsof

lsof not giving o/p for bash built in read


When I do

find /

on a terminal and then do on another terminal

lsof -a -d 0-2 -c fin

I see o/p listed from execution of lsof command.

But when I do

echo hi ; read -t 30 hello
hi

on the same terminal ( as find) and do (on different terminal)

lsof -a -d 0-2 -c read

I don't get any output from lsof command

Why ? Is it because read is bash built in ? Whats happening here ?


Solution

  • You got it right. "read" is a shell built-in. The process name remains sh (or bash, or zsh, or whatever else is your shell of choice).

    Moreover, though for some shell built-ins there are binary alternatives, there isn't one for read. Really because of its syntax, it takes in the name of a shell variable that gets assigned the result of reading from the stdin. If it was an external program, it could never set the variable in the calling shell.