Difference between “system” and “exec” in Linux?

前端 未结 12 1919
天命终不由人
天命终不由人 2020-11-28 05:18

What is the difference between system and exec family commands? Especially I want to know which one of them creates child process to work?

12条回答
  •  孤独总比滥情好
    2020-11-28 05:50

    System() will create child process and invoke another sub shell while exec() will not create child process.Given Example will clear difference.

    some code...

    exec('ls -l')

    echo "1 2 3" // This will not executed in bash (as exec command use same shell)

    some code ...

    system (ls -l) echo "1 2 3" // This will be executed after finishing System child process as they are different from parent PID.

提交回复
热议问题