管道和FIFO额外属性

管道和FIFO,若是在读模式打开以前没有以写模式打开,那么将一直阻塞下去。函数

FIFO只能用于单台主机上通讯,不能在NFS文件系统上通讯。测试

FIFO是能够经过open打开的,这时,咱们就能够启用O_NONBLOCK标志。大数据

可是对于管道来讲,因其没有open步骤,因此咱们经过fcntl()函数进行修改。code

#include <unistd.h>
#include <fcntl.h>
int fcntl(int fd, int cmd, ... /* arg */ );

 

OPEN_MAX:一个进程在任意时刻能够打开的最大描述符,用sysconf()函数测量。进程

#include <unistd.h>
long sysconf(int name);

PIPE_BUF:若是写入的数据小于PIPE_BUF,那么write操做保证是原子的,也就是说能够原子地写入一个管道或FIFO的最大数据量。ip

PIPE_BUF一般定义在<limits.h>头文件中,可是POSIX认为它是一个路径名变量,这意味着它的值能够随指定的路径名而变化。cmd

#include <unistd.h>
long fpathconf(int fd, int name);
long pathconf(char *path, int name);it

代码:pip

/*打印系统中的PIPE_BUF,OPEN_MAXA*/
//pipeconf.c
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    if (argc != 2) {
        printf("usage: pipeconf<pathname>\n");//提示要输入路径
        exit(1);
    }

    printf("PIPE_BUF = %ld, OPEN_MAX = %ld\n",pathconf(argv[1], _PC_PIPE_BUF), sysconf(_SC_OPEN_MAX));
    exit(0);//用pathconf,sysconf测试这两个系统变量
}
相关文章
相关标签/搜索