execve() 无法启动 C 程序
我正在尝试在 Linux 上使用 unistd.h
中的 execve()
生成一个新进程。我尝试向其传递以下参数 execve("/bin/ls", "/bin/ls", NULL);
但没有得到结果。我也没有收到错误,程序只是退出。发生这种情况有原因吗?我尝试以 root 和普通用户身份启动它。我需要使用 execve() 的原因是因为我试图让它在程序集调用中工作,就像这样
program: db "/bin/ls",0
mov eax, 0xb
mov ebx, program
mov ecx, program
mov edx, 0
int 0x80
谢谢!
I am trying to spawn a new process using execve()
from unistd.h
on Linux. I have tried passing it the following parameters execve("/bin/ls", "/bin/ls", NULL);
but get no result. I do not get an error either, the program just exits. Is there a reason why this is happening? I have tried launching it as root and regular user. The reason I need to use execve()
is because I am trying to get it to work in an assembly call like so
program: db "/bin/ls",0
mov eax, 0xb
mov ebx, program
mov ecx, program
mov edx, 0
int 0x80
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您传递给
execve
的参数是错误的。第二个和第三个必须是具有 NULL 标记值的 char 指针数组,而不是单个指针。换句话说,就像:
当我运行它时,我确实得到了当前目录中的文件列表。
The arguments that you're passing to
execve
are wrong. Both the second and third must be an array of char pointers with a NULL sentinel value, not a single pointer.In other words, something like:
When I run that, I do indeed get a list of the files in the current directory.
从 man 页面,
所以你的情况的问题是你没有通过第二个和第三个参数正确。
运行如下:
From the man pages,
So the problem in your case is that you haven't passed the 2nd and the 3rd argument correctly.
Run this as:
尝试再次阅读
man execve
。您向其传递了错误的参数。特别注意第二个参数应该是什么。另外,在
strace
下运行您的程序可能会很有启发。Try reading
man execve
again. You are passing the wrong arguments to it. Pay particular attention to what the second argument should be.Also, running your program under
strace
could be illuminating.