简体   繁体   English

Linux Shell在运行一个应用程序的多个实例时挂起

[英]Linux shell hangs on running multiple instances of an application

I am running a 'flute' (a protocol for sending multicast traffic) application/binary (which I downloaded) from C program by popen(). 我正在通过popen()从C程序运行“ flute”(发送多播通信的协议)应用程序/二进制文件(已下载)。 This application has a feature/bug that it doesn't run in background, since it uses the shell to take some commands. 该应用程序具有一个功能/错误,该功能/错误不会在后台运行,因为它使用外壳程序执行一些命令。 And during the run, the application locks the shell. 在运行期间,应用程序将锁定外壳。 That means you can only type some pre-defined letters in the shell, otherwise you have to wait till the end. 这意味着您只能在shell中键入一些预定义的字母,否则必须等到最后。 So, when I run multiple instances of the application using popen() from c code, the shell hangs permanently, probably because both applications tries to use it simultaneously (my assumption). 因此,当我从c代码使用popen()运行应用程序的多个实例时,shell会永久挂起,这可能是因为两个应用程序都试图同时使用它(我的假设)。 But I can manually run multiple instances in different shells. 但是我可以在不同的shell中手动运行多个实例。 Here is the sample code to run it from C program. 这是从C程序运行它的示例代码。

FILE* pF = popen("./flute -send -a226.0.0.1/6789 /media/song.mp3", "r");

Is there any solution so that the shell doesn't hang. 有什么解决方法可以防止外壳挂起。 Please help. 请帮忙。

If the process is just hanging because it wrote a prompt to your pF and is now blocked reading from the inherited stdin, you could: 如果该进程只是因为它向您的pF发出了提示而挂起,现在被阻止从继承的stdin中读取,则可以:

  • forward the prompt read from pF to stdout so it shows up on the terminal - then you'll know when/what to type 将从pF读取的提示转发到stdout以便其显示在终端上-然后您将知道何时/该输入什么
  • or manually fork and intercept both stdin and stdout : then the prompt won't go to your terminal, and your program can send the "pre-defined letters" programmatically 或手动fork并拦截stdinstdout :提示将不会进入您的终端,并且您的程序可以以编程方式发送“预定义字母”

If the process is hanging because it's really doing something with the inherited terminal, you can create a pseudoterminal for each child process, so they're not messing with the same controlling terminal. 如果该进程因正在使用继承的终端确实在做某事而挂起,则可以为每个子进程创建一个伪终端,这样它们就不会与同一个控制终端发生混乱。 See this question for reference. 请参阅此问题以供参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM