本文介绍了wait((int *)0)的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这样的等待功能的这样的程序是这样的:

One such program that uses a wait function like this is this one:

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int pid,fd[2]; int n; char line[20];
    if(pipe(fd)<0) {
        printf("Error creating pipe");
    } else {
        pid=fork();
        if(pid<0) {
            printf("Error while forking");
        } else {
            if(pid>0) {
                close(fd[0]);
                write(fd[1],"Hello\n",6);
                while(wait((int *)0)!=pid);
            } else {
                close(fd[1]);
                n=read(fd[0],line,20);
                if(n<0)
                printf("Error reading a file");
                write(1,line,n);
            }
        }
    }
    return 0;
}

推荐答案

stager的答案是正确的.尽管应该指出,强制转换完全没有必要,因为根据标准,指针上下文中使用的0是NULL指针.

stager's answer is correct. Though it should be noted that the cast is entirely unnecessary since according to the standard, 0 used in a pointer context is the NULL pointer.

这篇关于wait((int *)0)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:03
查看更多