mkfifo

can not open FIFO

与世无争的帅哥 提交于 2021-01-29 14:48:08
问题 I write this program to test the FIFO in Ubuntu。The main program create a child process to write something ,and then the parent read and print it /* communication with named pipe(or FIFO) @author myqiqiang @email myqiqiang@gmail.com */ #include<sys/types.h> #include<sys/stat.h> #include<stdio.h> #include<errno.h> #include<fcntl.h> #include<string.h> #define FIFO_SERVER "/home/myqiqiang/fifoserver" //fifo directioy #define BUFFERSIZE 80 void main() { pid_t pc; int flag,fd; char data[BUFFERSIZE

Read from n pipes from one process in parallel

三世轮回 提交于 2021-01-07 02:30:38
问题 I faced a concurrency problem when writing to the same named pipe created with mkfifo by multiple processes at the same time, where some writes got lost. Since the number of writing processes are limited I want to switch from "writing to 1 pipe from n processes and reading from 1 separate" to "writing to n pipes by n processes and reading from 1 separate process". Currently I'm reading via read line <"$pipe" in a loop until a condition is met. read blocks here until a line was read. How can I

Read from n pipes from one process in parallel

折月煮酒 提交于 2021-01-07 02:28:30
问题 I faced a concurrency problem when writing to the same named pipe created with mkfifo by multiple processes at the same time, where some writes got lost. Since the number of writing processes are limited I want to switch from "writing to 1 pipe from n processes and reading from 1 separate" to "writing to n pipes by n processes and reading from 1 separate process". Currently I'm reading via read line <"$pipe" in a loop until a condition is met. read blocks here until a line was read. How can I

Writing from multiple processes launched via xargs to the same fifo pipe causes lines to miss

别等时光非礼了梦想. 提交于 2020-12-15 07:14:38
问题 I have a script where I parallelize job execution while monitoring the progress. I do this using xargs and a named fifo pipe. My problem is that I while xargs performs well, some lines written to the pipe are lost. Any idea what the problem is? For example the following script (basically my script with dummy data) will produce the following output and hangs at the end waiting for those missing lines: $ bash test2.sh Progress: 0 of 99 DEBUG: Processed data 0 in separate process Progress: 1 of

【IPC通信】有名管道FIFO

冷暖自知 提交于 2020-04-17 02:21:08
【推荐阅读】微服务还能火多久?>>> 前面学习过(匿名)管道(见前面博客),匿名管道只能用于有亲缘关系的各个进程之间,为了解决这个限制,UNIX系统进而引入了FIFO,也称为有名管道(named pipe)。 FIFO(first in, first out),是一个半双工数据流,也即一个半双工管道。不同于匿名管道的是,每个FIFO有一个路径名(或文件名)与之关联,也即FIFO的名字。有了名字,无亲缘关系的进程间就可以通过管道进行数据传输了。 创建FIFO的方式: 使用shell命令 mkfifo创建一个有名管道 使用C库函数mkfifo创建一个有名管道 使用shell命令 mkfifo创建一个有名管道 [infor@s123 FIFO]$ mkfifo npipe [infor@s123 FIFO]$ ls -l prw-r--r-- 1 infor app 0 Nov 13 11:32 npipe 上面我们创建了一个有名管道npipe,我们可以看到有名管道其实是一个文件,文件类型是“p”,管道类型。 我们在开启两个终端,分别为A和B。在A终端下将数据写入管道,在B终端下将数据读出来。 [infor@s123 FIFO]$ ping 10.4.123.124 >> npipe #会阻塞在这里,等待另一个进程读 在终端A下将ping的结果写入管道npipe

Linux Shell 多线程编程-转贴

[亡魂溺海] 提交于 2020-02-29 10:08:01
#!/bin/bash #———————————————————————————– # 此例子说明了一种用wait、read命令模拟多线程的一种技巧 # 此技巧往往用于多主机检查,比如ssh登录、ping等等这种单进程比较慢而不耗费cpu的情况 # 还说明了多线程的控制 #———————————————————————————– function a_sub { # 此处定义一个函数,作为一个线程(子进程) sleep 3 # 线程的作用是sleep 3s } tmp_fifofile="/tmp/$$.fifo" mkfifo $tmp_fifofile # 新建一个fifo类型的文件 exec 6<>$tmp_fifofile # 将fd6指向fifo类型 rm $tmp_fifofile thread=15 # 此处定义线程数 for ((i=0;i<$thread;i++));do echo done >&6 # 事实上就是在fd6中放置了$thread个回车符 for ((i=0;i<50;i++));do # 50次循环,可以理解为50个主机,或其他 read -u6 # 一个read -u6命令执行一次,就从fd6中减去一个回车符,然后向下执行, # fd6中没有回车符的时候,就停在这了,从而实现了线程数量控制 { # 此处子进程开始执行,被放到后台 a_sub &&

FIFO server program

≯℡__Kan透↙ 提交于 2019-12-25 10:02:08
问题 The above program i have typed in linux. It basically has to connect a client and server in separate terminals. But when i run them in the correct order, i.e Compile server -> run server Compile client - > run client The terminals just dont do anything. It doesnt even print the "Trying to connect" part of the first printf statement. What is the mistake here? EDIT I checked for return value of mkfifo as @parapura rajkumar said. But Still it remains the same. Here is my changed code for server.

FIFO server program

↘锁芯ラ 提交于 2019-12-25 10:00:11
问题 The above program i have typed in linux. It basically has to connect a client and server in separate terminals. But when i run them in the correct order, i.e Compile server -> run server Compile client - > run client The terminals just dont do anything. It doesnt even print the "Trying to connect" part of the first printf statement. What is the mistake here? EDIT I checked for return value of mkfifo as @parapura rajkumar said. But Still it remains the same. Here is my changed code for server.

mkfifo causes terminal to hang?

梦想与她 提交于 2019-12-20 04:04:17
问题 Does mkfifo simply not work with Cygwin? A simple set of commands such as $ mkfifo my_pipe $ echo "1234" > my_pipe just causes the terminal to sit forever with the cursor blinking. Am I "doing it wrong"? 回答1: No, you're not doing anything wrong with either of those commands, it's just your expectations are a little off. What you're missing is something at the other end of that pipe, reading that data. This apparent hanging happens in Linux as well, so it's not a CygWin problem (or any sort of

fifo - reading in a loop

这一生的挚爱 提交于 2019-12-12 08:25:35
问题 I want to use os.mkfifo for simple communication between programs. I have a problem with reading from the fifo in a loop. Consider this toy example, where I have a reader and a writer working with the fifo. I want to be able to run the reader in a loop to read everything that enters the fifo. # reader.py import os import atexit FIFO = 'json.fifo' @atexit.register def cleanup(): try: os.unlink(FIFO) except: pass def main(): os.mkfifo(FIFO) with open(FIFO) as fifo: # for line in fifo: # closes