初学,关于帮助文件的问题

中文QNX 讨论: 欢迎大家灌水,讨论有关QNX 问题。

初学,关于帮助文件的问题

帖子arle » 周二 9月 13, 2011 3:27 pm

我将 help 中的例子拷贝,为什么多数是编译报错?不报错的,运行又是失败?像创建进程的例子,创建就不成功。附个例子完全是help中的:
/*
* waitchild.c
*
* This is an example of a parent process that creates some child
* processes and then waits for them to terminate. The waiting is
* done using wait(). When a child process terminates, the
* wait() function returns.
*/

#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>


main(int argc, char **argv)
{
char *args[] = { "child", NULL };
int i, status;
pid_t pid;
struct inheritance inherit;

// create 3 child processes
for (i = 0; i < 3; i++) {
inherit.flags = 0;
if ((pid = spawn("child", 0, NULL, &inherit, args, environ)) == -1)
perror("spawn() failed");
else
printf("spawned child, pid = %d\n", pid);
}

while (1) {
if ((pid = wait(&status)) == -1) {
perror("wait() failed (no more child processes?)");
exit(EXIT_FAILURE);
}
printf("a child terminated, pid = %d\n", pid);

if (WIFEXITED(status)) {
printf("child terminated normally, exit status = %d\n",
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("child terminated abnormally by signal = %X\n",
WTERMSIG(status));
} // else see documentation for wait() for more macros
}
}
arle
New Member
 
帖子: 1
注册: 周二 9月 13, 2011 3:15 pm

回到 四海同心QNX论坛

在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客