I'm trying to understand some kernel level concepts in Linux. I was checking on the difference between shell builtin commands and the other executable commands.
This wonderful answer clearly tells the difference and also specifies the need for shell builtin commands.
Now I know that using type <command-name>
, I could check if it is an external or shell builtin command.
So I decided to do some strace
'ing on the various commands to understand more of the internals.
I learned this neat little trick to do strace
'es on shell builtin commands. I was able to do strace
on cd ..
as well according to the above answer.
Now when I run type pwd
and get the output as, pwd is a shell builtin
. So, I expect that I wouldn't be able to run strace
on it, since it too is a shell builtin. But when I did an strace
on it, I was surprised to see that strace
worked without the need to do stty
.
I verified strace
for echo
as well and it worked fine too.
So my understanding is, that strace
worked in the case of pwd
and echo
because the execution of pwd
and echo
did not change any of the shell's behavior.
Am I correct in my understanding?
echo
andpwd
are 2 such commands, so you're stracing the standalong counterparts and not the built-ins when you did the above tests. – slm Sep 09 '14 at 02:17type -a
. – Ramesh Sep 09 '14 at 02:21strace
, chances are thatstrace cd
will work withoutstty
. Is this understanding correct? – Ramesh Sep 09 '14 at 02:33strace
it. But aliases and functions etc. are built into Bash and cannot be straced, since you'd have tostrace
Bash itself to watch them. – slm Sep 09 '14 at 02:35strace
. There are no system calls to trace for a builtin since it's doing everything internal to Bash. – slm Sep 09 '14 at 02:37