https://elixir.bootlin.com/linux/v5.19/source/fs/pipe.c#L247
当一个管道满了的时候,它不应该唤醒读者读出数据吗?
/*
* We only wake up writers if the pipe was full when we started
* reading in order to avoid unnecessary wakeups.
*
* But when we do wake up writers, we do so using a sync wakeup
* (W
如何在linux管道上设置写()的超时?
示例代码:
int fd_pipe = open("/run/some/pipe", O_RDWR);
// here i need to set timeout for 3 seconds somehow, if can't write, code will continue...
write(fd_pipe, something, strlen(something));
// continue executing..
谢谢
可能重复:
在linux中,哪个头文件指定管道上可写的大小?
我捕获每个可配置周期的主应用程序的延迟,并将这些数据写入管道。一个单独的报告过程可以读取该管道。通常,主应用程序每秒交换大约10,000条消息。因此,给定1秒的周期,主应用程序为每个消息交换收集10k延迟数据点,然后将它们写入秒边界上的管道。在这个场景中,我有以下问题
- Is there way to specify the size of pipe while creation,so i can ensure there is adequate write space in the pipe?
-
我从linux中的C++程序启动程序,如下所示:
char* cmd = "/bin/snmpd &"; // command to execute
FILE* pipe = popen(cmd, "r"); // pipe to command line
if (!pipe) return -1; // check if pipe worked
pclose(pipe); // close pipe
return 1;
我刚刚观察到,在二元结构中,失速现象非常罕见。
将gdb附加到相关线程并切换到相应线程
(gdb) bt
#0 0x000000330a4db79d in write () from /lib64/libc.so.6
#1 0x000000330a471dd3 in _IO_new_file_write () from /lib64/libc.so.6
#2 0x000000330a473385 in _IO_new_do_write () from /lib64/libc.so.6
#3 0x000000330a4726df in _IO_new_file_overflow () f
在网上做了一些搜索,找到了使用命名管道的简单“教程”。然而,当我做任何后台工作时,我似乎丢失了很多数据。
[编辑:找到了一个更简单的解决方案,请参阅回复帖子。因此,我提出的问题现在是学术问题-以防有人可能需要作业服务器]
Ubuntu 10.04与Linux2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux
GNU bash,版本4.1.5(1)-release (x86_64-pc-linux-gnu)。
我的bash函数是:
function jqs
{
pipe=/tmp/__j
我试图在C中实现一个Linux管道链,例如:
grep file | ls | wc
因此,有一个代码将参数拆分为以管道为分隔符的标记,并将每个部分发送到下面的函数,其中包含一个整数,指定它是否位于管道之前:
int control_flow(char** args, int precedes){
int stdin_copy = dup(0);
int stdout_copy = dup(1);
// if the command and its args precedes a pipe
if (precedes){
int fd[2];
我是新来的Go,我想在Go中创建命名管道实现,它可以在Windows和Linux上工作。
我设法让代码在Ubuntu上运行,但这个不能在Windows上运行
Go中是否有任何抽象允许您在这两种环境中使用命名管道
下面是我的代码片段
//to create pipe: does not work in windows
syscall.Mkfifo("tmpPipe", 0666)
// to open pipe to write
file, err1 := os.OpenFile("tmpPipe", os.O_RDWR, os.Mode
const p = spawn('ls', ['/'])
console.log('$mark$')
p.stdout.pipe(process.stdout)
上面的代码准确地打印根目录的文件列表,即:
$mark$
bin
boot
data
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
solr.log
srv
sys
tmp
usr
var
但是,如果我等一下,比如1秒,它就什么也不打印了。守则如下:
const p = spawn('ls