为什么子bash不继承其父代的变量?

时间:2018-11-15 04:55:42

标签: c shell

我正在学习fork

   fork() creates a new process by duplicating the calling process.  The
   new process is referred to as the child process.  The calling process
   is referred to as the parent process.

   The child process and the parent process run in separate memory
   spaces.  At the time of fork() both memory spaces have the same
   content.  Memory writes, file mappings (mmap(2)), and unmappings
   (munmap(2)) performed by one of the processes do not affect the
   other.

子进程与父进程完全相同。

但是,当涉及到bash时

[root@iz2ze9wve43n2nyuvmsfx5z ~]# a=3
[root@iz2ze9wve43n2nyuvmsfx5z ~]# bash
[root@iz2ze9wve43n2nyuvmsfx5z ~]# echo $a

[root@iz2ze9wve43n2nyuvmsfx5z ~]# ps --forest
  PID TTY          TIME CMD
32621 pts/1    00:00:00 bash
32644 pts/1    00:00:00  \_ bash
32675 pts/1    00:00:00      \_ ps

为什么bash不直接继承父内容。

我认为它也应该以{{1​​}}为基础来实现。

但是它继承了父变量,必须使用export。

0 个答案:

没有答案