为什么 execv 可能会崩溃?
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main (int argc, const char * argv[])
{
printf("start\n");
char *const parmList[] = {"/bin/ls", "-l", NULL};
execv("/bin/ls", parmList);
return 0;
}
我用 GCC4.2 编译 你知道为什么这可能会崩溃吗?我在 xcode 中没有收到任何错误消息。
编辑:用户错误。 “崩溃”意味着 xcode 在运行程序时冻结了。按继续效果很好。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main (int argc, const char * argv[])
{
printf("start\n");
char *const parmList[] = {"/bin/ls", "-l", NULL};
execv("/bin/ls", parmList);
return 0;
}
I compiled with GCC4.2 Any ideas why this might crash? I'm not getting any error messages in xcode.
EDIT: user error. "crash" meant xcode froze when it ran the program. Pressing continue works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码在我的环境(Ubuntu 10 下的 gcc 4.4.3)中运行和编译良好。这让我相信您遇到的问题与您认为的问题不同:-)
尝试以下代码以查看实际的
exec
失败。如果是,它应该告诉你原因。如果不是,那么您根本看不到 rc 输出。还要检查以确保
/bin/ls
是您期望的内容(例如,可执行文件,而不是脚本)。值得澄清一下“崩溃”的含义。它只是不产生任何输出吗?它转储核心文件吗?它是否会使您的整个操作系统瘫痪,导致重新启动?
That code runs and compiles fine in my environment, gcc 4.4.3 under Ubuntu 10. That leads me to believe that you have a different problem from the one you think you have :-)
Try the following code to see if the actual
exec
is failing. If it is, it should tell you why. If it isn't, then you won't see therc
output at all.Also check to make sure the
/bin/ls
is what you expect it to be (an executable, not a script, for example).And it's worth clarifying what you mean by "crash". Is it just not producing any output? It it dumping a core file? Is it bringing your entire OS to its knees, causing a reboot?