另一种方法是用popen pipe执行程序并读取输出 [英] Alternative for popen pipe to execute program and read the output

查看:242
本文介绍了另一种方法是用popen pipe执行程序并读取输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请为 popen()建议良好的替代方法,以执行shell命令,然后读取输出。

Please, suggest good alternative for popen() to execute shell commands and then read the output.

EDIT:替代方案必须没有 fork()调用。因为我的服务器已经占用了太多的内存。然后 ffmpeg 还需要内存和进程大小增加!我每次都会遇到 fork()的问题。

The alternative must be without fork() call. Because my server is already takes too much memory. Then ffmpeg need also memory and process size is increased! and I get the problems to fork() to memory weight server each time.

推荐答案

如果您担心在分叉时复制父进程的内存,则需要使用 vfork() - 特殊版本的fork,不会复制父进程的内存但是需要分叉的进程立即发出 execve()

If you worry about copying the memory of the parent process when forking, then you need to use vfork() - a special version of "fork" that does not copy the memory of a parent process but requires the forked process to immediately issue execve().

这篇关于另一种方法是用popen pipe执行程序并读取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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