简体   繁体   中英

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(). 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. 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). But I can manually run multiple instances in different shells. Here is the sample code to run it from C program.

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:

  • forward the prompt read from pF to stdout so it shows up on the terminal - then you'll know when/what to type
  • 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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