【发布时间】:2021-11-21 15:15:58
【问题描述】:
我正在尝试获取管道的大小:
printf("pipe 0 size: %d bytes\npipe 1 size: %d bytes\n", fcntl(fd[0], F_GETPIPE_SZ), fcntl(fd[1], F_GETPIPE_SZ));
使用的标头(其中一半被另一部分代码使用):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
当我尝试编译时,gcc 失败并出现以下错误:
‘F_GETPIPE_SZ’未声明(在此函数中首次使用)
内核版本 - 5.4.0-88-generic
libc6-dev 版本 - 2.31-0ubuntu9.2
gcc 版本 - 4:9.3.0-1ubuntu2
【问题讨论】:
-
阅读手册页
man fcntl,它提到你需要__GNU_SOURCE的宏F_GETPIPE_SZ