Skip to main content
Typo
Source Link
The Quark
  • 454
  • 3
  • 14

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"? and the POSIX definitions of subshell and child process).

To convincedconvince myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"? and the POSIX definitions of subshell and child process).

To convinced myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"? and the POSIX definitions of subshell and child process).

To convince myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

added 229 characters in body
Source Link
The Quark
  • 454
  • 3
  • 14

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"? and the POSIX definitions of subshell and child process).

To convinced myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"?).

To convinced myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"? and the POSIX definitions of subshell and child process).

To convinced myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17

Source Link
The Quark
  • 454
  • 3
  • 14

Example of subshell without child-shell process

I just recently learned that "subshell" is not the same as "child shell process" (see for example What is the exact difference between a "subshell" and a "child process"?).

To convinced myself of this, I am looking for a command that illustrates (proves) that a subshell is created without a child-shell being spawned.

For now, everything I tried seemed to spawn a child-shell whenever a subshell is created:

$ echo $BASHPID; (pwd; cd ..; echo $BASHPID; pwd); pwd      # `( ...)` executed in a subshell
                                                            # and in a child-shell process

$ >&2 ps | ps       # Theoretically executed in two subshells and apparently without child-shells
                    # but I cannot be sure due to the outcome of the next example

$ $ >&2 echo $BASHPID | ps      # `ps` doesn't display a child-shell for the execution of `echo`
953790                          # but `echo $BASHPID` shows a new process that is necessarily
    PID TTY         TIME CMD    # a child-shell since echo is a built-in 
 948538 pts/2   00:00:00 bash
 953791 pts/2   00:00:00 ps

I am looking for a way to demonstrate that having a subshell doesn't necessarily imply having a child-shell...

Bash 5.0.17