当 std=c99 时,如何使用 exec/kill ?

发布于 2024-12-17 05:09:20 字数 429 浏览 2 评论 0原文

当我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧幽蓝 2024-12-24 05:09:20

根据您的包含内容,您似乎正在使用某种 Unix。没有 exec 调用。有 execlexexlp 等,其名称取决于参数的确切类型。有关详细信息,请查看“exec”的手册页。

Based on your includes, it appears like you're using a Unix of some kind. There is no exec call. There is execl, exexlp, and others with names depending on the exact types of parameters. Check the man page for 'exec' for details.

梦幻的心爱 2024-12-24 05:09:20

您需要#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文