Execute shell command using threads c++

后端 未结 1 641
眼角桃花
眼角桃花 2021-01-21 11:01

Is it possible to execute a shell command by creating a thread i.e. without using popen/system or any of the fork-exec variants? Why or why not?

To provide more context,

相关标签:
1条回答
  • 2021-01-21 11:07

    Here's an useful summary on the multi-threading & fork+exec potential problems: http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

    It seems that if you want to execute other programs and even shell scripts, you have to use fork+exec, it's unavoidable. Just be careful and prepare your threads for such a "bad" event like fork. Also you could close all unnecessary file descriptors in a special single threaded trusted execute helper being run from the main application, if that's the problem.

    0 讨论(0)
提交回复
热议问题