Skip to main content
2 of 5
added 58 characters in body
Tim
  • 106.8k
  • 234
  • 651
  • 1.1k

Compare running a command directly and in background

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 date is 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 9098 execve() the command.

    When running the command in background, the original bash shell 6913 clone() itself, and then its clone 9143 execve() the command.

    What are the differences between them?

Tim
  • 106.8k
  • 234
  • 651
  • 1.1k