In Ubuntu, I run date in an interactive bash shell whose pid is 6913, and at the same time, trace the bash shell from another interactive bash shell by strace.
By using tracing, I would like to understand how date is run directly (see here for tracing output) and in background (see here for tracing output):
It is said that a command running in background can access a local variable in the parent shell, because it runs in a subshell of the parent shell, while a command running directly can't, because it doesn't run in a subshell of the parent shell. Can we explain the difference using the outputs of tracing?
As far as running the command
dateis concerned, directly running it and running it in background seem to do the same thing:When running the command directly, the original bash shell 6913
clone()itself, and then its clone 9098execve()the command.When running the command in background, the original bash shell 6913
clone()itself, and then its clone 9143execve()the command.What are the differences between them?