Contents
Is the subshell a child process in Bash?
In bash a subshell is a child process, other shells differ but even then a variable setting in a subshell does not affect the caller.
When do you fork a child process in Bash?
Whenever an external command is executed, a child process is created. This action is termed forking. As ps -f is external command (i.e. An external command, sometimes called a filesystem command, is a program that exists outside of the bash shell.) this will create child process with parent id of bash shell from which it is executed.
Can a subshell affect the caller in Bash?
In bash a subshell is a child process, other shells differ but even then a variable setting in a subshell does not affect the caller. By definition.
Can a subshell have access to its parent’s stack?
The subshell doesn’t have access to its parent’s environment. (At least within the abstraction that Bash provides. You could potentially try to use gdb, or smash the stack, or whatnot, to gain such access clandestinely. I wouldn’t recommend that, though.)
What is a subreaper process in the Linux kernel?
This was implemented to the Linux kernel 3.4 as a flag of the system call prctl (). […] A subreaper fulfills the role of init (1) for its descendant processes.
How to change variable in parent script from subshell?
If the problem is related to a while loop, one way to fix this is by using Process Substitution: To change variables in a script called from a parent script, you can call the script preceded with a “.” You can output the value in the subshell and assign the subshell output to a variable in the caller script:
How to export Vars from subshell to parent shell?
Another approach. Just exec a subordinate $SHELL in your script, maybe with a different prompt (change $PS1 to notify users under which environment they are working to reduce confusion). Another approach (my favorite). Users forget to source your script, why is that?
How to separate a variable from a subshell?
If the subshell has more to output you can separate the variable value and other messages by redirecting them into different output streams: Alternatively, you can output variable assignments in the subshell, evaluate them in the caller script and avoid using files to exchange information: