问题描述
system()
函数是通过使用fork()
,execve()
和wait()
函数实现的.我听说fork()
函数在多线程程序中很危险.那么,system()
函数在多线程程序中是否也很危险?
system()
function is implemented by using fork()
, execve()
and wait()
functions.I have heard that fork()
function is dangerous in multi-threaded programs.So, is the system()
function also dangerous in multi-threaded programs?
它可能引起什么问题?
推荐答案
fork
在线程程序除非后跟execve
是危险的.由于只分叉了当前线程,因此除了execve
之外,您几乎无法在分叉的多线程程序中执行任何操作.您可能应该确保fork
之后没有锁.
fork
is dangerous in threaded programs unless followed by execve
. Since only the current thread is forked there's very little you can do in a forked multi-threaded program other than execve
. You should probably make sure you're not taking any locks after the fork
.
由于system()
执行fork
+ exec
,所以它应该是安全的.
Since system()
does fork
+ exec
, it should be safe.
这篇关于从多线程进程调用system(3)是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!