系统调用程序后不执行任何操作() [英] program not executing anything after a call to system()

查看:134
本文介绍了系统调用程序后不执行任何操作()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话通过系统(命令)调用的命令。但没有其他code是该系统后执行()调用。

I am calling a command via system(command) call. But no other code is executed after this system() call.

为什么会这样?我以为,系统()将创建命令的执行和我的程序(命令柴尔德的父)子进程将继续后执行code。

Why is so? I thought, system() would create a child process for "command" execution and my program (parent of "command"-child) will continue executing code after that.

难道我不理解系统()是否正确?

Am I not understanding system() correctly?

code:

printf("before \n");
system("tail -f filename");       /* long lived - never returns */
printf("after \n");

在这里,我没有得到过印后看。

Here, I do not see after getting printed ever.

推荐答案

的<一个href=\"http://www.kernel.org/doc/man-pages/online/pages/man3/system.3.html\"><$c$c>system(3)功能使你的进程等待孩子的完成。

The system(3) function causes your process to wait for the completion of the child.

您必须使用经典的对 叉(2) 和<一个href=\"http://www.kernel.org/doc/man-pages/online/pages/man2/execve.2.html\"><$c$c>execve(2)你想要做什么。你也可以检查你的C库是提供POSIX 重生(3)

You have to use the classic pair of fork(2) and execve(2) for what you want to do. You might also check whether your C library provides POSIX spawn(3).

。看看<一个href=\"http://www.kernel.org/doc/man-pages/online/pages/man2/waitpid.2.html\"><$c$c>waitpid(2)保持父左右。

Look into waitpid(2) to keep the parent around.

这篇关于系统调用程序后不执行任何操作()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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