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

  • 相关阅读:
    goreplay~基本知识
    goreplay~http输出队列
    goreplay~拦截器设置
    goreplay~流量变速
    goreplay~http过滤参数
    goreplay~文件输出解析
    goreplay~http输出工作线程
    Antlr4 语法解析器(下)
    2021最新版Eclipse的下载和使用
    MySQL中drop、truncate和delete的区别
  • 原文地址:https://www.cnblogs.com/cute/p/2095911.html
Copyright © 2011-2022 走看看