zoukankan      html  css  js  c++  java
  • source exec 区别(shell 13问中摘出)

    exec也是让script在同一个进程上执行,但是原有进程则被结束了

    脚本内容:

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# cat 1.sh
    #!/bin/sh
    A=B
    echo "PID for 1.sh :$$"
    export A
    echo "1.sh \$A is $A"
    case $1 in
            exec)
                    echo "using exec..."
                    exec ./2.sh;;
            source)
                    echo "using source..."
                    source ./2.sh;;
            *)
                    echo "using fork..."
                    ./2.sh;;
    esac

    echo "PID for 1.sh after run 2.sh: $$"
    echo "1.sh \$A is $A"

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# cat 2.sh
    #!/bin/sh
    echo "PID for 2.sh :$$"

    echo "2.sh get \$A=$A from 1.sh"
    A=C
    export A
    echo "2.sh \$A is $A"

    运行结果:

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh
    PID for 1.sh :8152
    1.sh $A is B
    using fork...
    PID for 2.sh :8153
    2.sh get $A=B from 1.sh
    2.sh $A is C
    PID for 1.sh after run 2.sh: 8152
    1.sh $A is B

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh source
    PID for 1.sh :8158
    1.sh $A is B
    using source...
    PID for 2.sh :8158
    2.sh get $A=B from 1.sh
    2.sh $A is C
    PID for 1.sh after run 2.sh: 8158
    1.sh $A is C

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh exec
    PID for 1.sh :8159
    1.sh $A is B
    using exec...
    PID for 2.sh :8159
    2.sh get $A=B from 1.sh
    2.sh $A is C

  • 相关阅读:
    关于JavaScript文档对象
    关于JavaScript浏览器对象
    关于JavaScript事件与函数
    关于JavaScript基础知识
    关于CSS基础知识
    第七章:Hexadecimal, octal, ASCII, UTF8, Unicode, Runes
    没有 Cgroups,就没有 Docker
    Redis 文件事件
    Python 垃圾回收总结
    Docker Bridge 网络原理
  • 原文地址:https://www.cnblogs.com/cute/p/2095911.html
Copyright © 2011-2022 走看看