c - 我如何在 Linux 中等待子进程完成

标签 c linux popen alsa

<分区>

我需要使用 aplay 播放一个 wave 文件。但是,我的波形文件只有几秒钟的长度。所以我打算在一段时间内循环播放它们。 aplay 似乎没有循环选项。从我的 C 文件创建一个子进程,使用 popen() 回放工作正常。但困难的是,我无法监控 wave 文件播放何时完成,以便我可以重新开始。

popen("aplay WaveFile","r");

我如何知道此命令何时完成播放?

提前致谢!

最佳答案

来自popen手册页:

The pclose() function waits for the associated process to terminate and returns the exit status of the command as returned by wait4(2).

如果你不想在pclose 时被阻止,你可以试试non-blocking readspopen 返回的管道上,直到你得到一个 EOF,这意味着进程已经终止。

关于c - 我如何在 Linux 中等待子进程完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51295094/

相关文章:

c - 使用 Libdl.dlopen 杀死 Julia

c - 如果我们在链表中查找循环时改变慢指针和快指针的跳数会怎样?

android - C 编译器 "clang.exe"无法编译简单的测试程序

linux - awk 解析输出并提取值

php - 如何在没有乱码的情况下用php下载zip

linux - 如何在 GDB 中运行以前的指令?

c - 在 popen 工作时缓冲

java - 需要帮助迭代在较大的二维数组中找到的较小的二维 "subarrays"

c - POpen 适用于字符串但不适用于变量

python - Popen 在可用时不会立即给出输出