当 std=c99 时,如何使用 exec/kill ?
当我尝试使用 exec:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
int main()
{
exec("echo `Hello World`");
return 0;
}
我收到此错误:
code.c:11: error: implicit declaration of function ‘exec’
make: *** [code.o] Error 1
我必须使用 std=c99 并且无法添加任何其他编译器标志。我如何使用 exec (或类似的调用)?
我想kill的解决方案是一样的,不是吗?
When I try to use exec:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
int main()
{
exec("echo `Hello World`");
return 0;
}
I get this error:
code.c:11: error: implicit declaration of function ‘exec’
make: *** [code.o] Error 1
I have to use std=c99 and I can't add any other compiler flags. How can I use exec (or a simmilar call)?
I guess the solution will be the same for kill, wouldn't it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的包含内容,您似乎正在使用某种 Unix。没有
exec
调用。有execl
、exexlp
等,其名称取决于参数的确切类型。有关详细信息,请查看“exec”的手册页。Based on your includes, it appears like you're using a Unix of some kind. There is no
exec
call. There isexecl
,exexlp
, and others with names depending on the exact types of parameters. Check the man page for 'exec' for details.您需要
#define _POSIX_C_SOURCE 200809L
或#define _XOPEN_SOURCE 700
,或者在编译器的命令行上使用等效的-D
选项。You need to
#define _POSIX_C_SOURCE 200809L
or#define _XOPEN_SOURCE 700
, or use the equivalent-D
options on the command line to the compiler.