从多线程进程调用system(3)是否安全? [英] Is it safe to call system(3) from multi-threaded process?

查看:312
本文介绍了从多线程进程调用system(3)是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆