mkfifo

Syntax to Redirect to Input/Output to in C (UNIX)

依然范特西╮ 提交于 2019-12-12 06:17:02
问题 I am trying to find the syntax that will let me redirect standard input output toward a named pipe after using the mkfifo() function and creating a child process using fork. Which man page should I be looking at for the syntax? Thanks, Aaron 回答1: Various sections of man page can serve your various purposes. Generally, Section 1 contain syntax for executable programs or shell command . man mkfifo Section 3 contain syntax for Library call ( used in c programs). man 3 mkfifo Edit: I think i

Having a trouble with opening FIFO in C

巧了我就是萌 提交于 2019-12-10 15:38:59
问题 I'm having a trouble in opening FIFOs in C.. first I created them using mkfifo() function with permission : 0777, and when I tried to open them, it succeeded in opening the first FIFO only, then the process will stuck in opening the second FIFO, and this is my code : fd1 = open("FIFO1_PATH", O_WRONLY ); fd2 = open("FIFO2_PATH", O_WRONLY ); This will not be executed, but once I comment the second line, it executes ! Is there a limit for the number of opening FIFOs per process ? I don't know

Python and FIFOs

不想你离开。 提交于 2019-12-07 03:40:13
问题 I was trying to understand FIFOs using Python under linux and I found a strange behavior i don't understand. The following is fifoserver.py import sys import time def readline(f): s = f.readline() while s == "": time.sleep(0.0001) s = f.readline() return s while True: f = open(sys.argv[1], "r") x = float(readline(f)) g = open(sys.argv[2], "w") g.write(str(x**2) + "\n") g.close() f.close() sys.stdout.write("Processed " + repr(x) + "\n") and this is fifoclient.py import sys import time def

Python and FIFOs

柔情痞子 提交于 2019-12-05 08:00:50
I was trying to understand FIFOs using Python under linux and I found a strange behavior i don't understand. The following is fifoserver.py import sys import time def readline(f): s = f.readline() while s == "": time.sleep(0.0001) s = f.readline() return s while True: f = open(sys.argv[1], "r") x = float(readline(f)) g = open(sys.argv[2], "w") g.write(str(x**2) + "\n") g.close() f.close() sys.stdout.write("Processed " + repr(x) + "\n") and this is fifoclient.py import sys import time def readline(f): s = f.readline() while s == "": time.sleep(0.0001) s = f.readline() return s def req(x): f =

fifo - reading in a loop

只愿长相守 提交于 2019-12-04 03:18:41
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 after single reading # for line in fifo.readlines(): # closes after single reading while True: line =

C++ Linux named pipe hanging on open() with O_WRONLY

两盒软妹~` 提交于 2019-11-30 22:28:37
This is my simple code that opens a named pipe, writes a string to it, and then closes the pipe. The pipe is created in a another function, as mentioned below. char * ipcnm = "./jobqueue"; std::cout << "opening job queue" << std::endl; //ensure the jobqueue is opened if ((jobq = open(ipcnm, O_WRONLY)) < 0) { perror("open"); exit(-1); } std::cout << "queue opened" << std::endl; // record the number of bytes written to the queue size_t written = write(jobq, ptr, size*nmemb); // close fifo if (close(jobq) < 0) { perror("close"); exit(-1); } // need to report to other agents the size of the job

C++ Linux named pipe hanging on open() with O_WRONLY

爷,独闯天下 提交于 2019-11-30 18:26:43
问题 This is my simple code that opens a named pipe, writes a string to it, and then closes the pipe. The pipe is created in a another function, as mentioned below. char * ipcnm = "./jobqueue"; std::cout << "opening job queue" << std::endl; //ensure the jobqueue is opened if ((jobq = open(ipcnm, O_WRONLY)) < 0) { perror("open"); exit(-1); } std::cout << "queue opened" << std::endl; // record the number of bytes written to the queue size_t written = write(jobq, ptr, size*nmemb); // close fifo if

How do I use exec 3>myfifo in a script, and not have echo foo>&3 close the pipe?

夙愿已清 提交于 2019-11-29 11:55:43
Why can't I use exec 3>myfifo in the same manner in a bash script as I can in my terminal? I'm using named pipes to turn an awk filter into a simple "server", that should be able to take text input from clients, filter it, and flush on NUL. In terminal 1, the server is running like this: $ mkfifo to_server from_server; $ while true; do # Really, this awk script BEGIN's with reading in a huge file, # thus the client-server model awk '{sub("wrong", "correct");print;} /\0/ {fflush();}' <to_server >from_server; echo "restarting..."; done And I've got a simple script that should put input, ending

PhantomJS: pipe input

99封情书 提交于 2019-11-29 03:27:56
I am trying to use PhantomJS to render an html page to pdf. I do not want to write the files to disk, I have the html in memory, and I want the pdf in memory. Using the excellent answer from Pooria Azimi at this question , i am able to get the pdf from a named pipe. When trying the same on the other end (replacing the input file with a named pipe), I end up with a blank pdf. This is what I am doing now (simplified): mkfifo in_pipe.html out_pipe.pdf ./phantomjs rasterize.js in_pipe.html out_pipe.pdf Then in another terminal: echo '<center>hey!</center>' > in_pipe.html cat out_pipe.pdf > out.pdf

How do I properly write to FIFOs in Python?

◇◆丶佛笑我妖孽 提交于 2019-11-29 03:12:32
Something very strange is happening when I open FIFOs (named pipes) in Python for writing. Consider what happens when I try to open a FIFO for writing in a interactive interpreter: >>> fifo_write = open('fifo', 'w') The above line blocks until I open another interpreter and type the following: >>> fifo_read = open('fifo', 'r') >>> fifo.read() I don't understand why I had to wait for the pipe to be opened for reading, but lets skip that. The above code will block until there's data available as expected. However let's say I go back to the first interpreter window and type: >>> fifo_write.write(