I'm trying to change pipe size using F_SETPIPE_SZ but when compiling it says it is undeclared?

StackOverflow https://stackoverflow.com/questions/16863914

  •  30-05-2022
  •  | 
  •  

#include <unistd.h>
#include <fcntl.h>

int exec[2];
int pipesize = 8192;

if(pipe(exec) ==-1) {
  perror("pipe");
  return -1;
}

fcntl(exec[1],F_SETPIPE_SZ,&pipesize);

I'm running this code but i get an error saying F_SETPIPE_SZ is undeclared. I'm using Ubuntu 13.04, what may be the problem?

有帮助吗?

解决方案

F_SETPIPE_SZ is Linux specific. You need to add:

#define _GNU_SOURCE

before including fcntl.h. This is documented in the Conforming to section in the man page.

Note however that the default size should be enough for most uses of pipes for IPC with concurrent reads and writes, as pipe size is relevant only to reduce context switching. If you need a large pipe because you're storing data for long periods (e.g., because the reader is not active), you should consider rethinking your solution using temporary files, as very large pipes will waste kernel memory.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top