Difference between using fork/execvp and system call

前端 未结 5 1277
小鲜肉
小鲜肉 2021-02-07 12:13

What is the difference between using system() to execute a binary and using the combination of fork/execvp.

Is there any security/portablility/performance difference.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 12:33

    System also uses a fork/exec... combination. If you do fork/exec yourself you can execute parallel to your running process, while system is blocking (includes the wait). Also system executes the command not direct, but via a shell (which makes problems with setuid bit) and system blocks/ignores certain signals (SIGINT, SIGCHILD, SIGQUIT).

提交回复
热议问题