Pstree
echo $$//Current process PID
Echo $PPID//Parent process ID
Sub-process test:
New file:
[Email protected]]~ # VI bashpid.sh
#!/bin/bash
Echo $BASHPID
//测试[[email protected]]~ # echo $BASHPID //当前shell 6136 //结果[[email protected]]~ # bash bashpid.sh 6550 //结果[[email protected]]~ # source ./bashpid.sh //不开启shell子进程 6136 //结果与当前shell结果一样[[email protected]]~ # ./bashpid.sh //开启子shell运行脚本 6555[[email protected]]~ # (echo $BASHPID) //小括号表示进入子shell执行命令 6558[[email protected]]~ # { echo $BASHPID; } //花括号表示在当前shell执行命令 6136 //结果与当前shell结果一样
Variables can only be passed down, inherited, not uploaded, inherited
#name =parent; (echo "1: $name"; Name=son;echo "2: $name"); echo "3: $name"//parenthesis () Open the child shell to enter the child shell
1:parent
2:son
3:parent
Curly braces {} Do not open sub-shell,shell programming may be used.
Name=parent; {echo "1: $name"; Name=son;echo "2: $name";}; echo "3: $name"//curly braces do not enter the child shell
1:parent 2:son 3:son
Child shell Test