Answer the question
In order to leave comments, you need to log in
How to run two processes at the same time?
Problem about Producer&Consumer. The purpose of the task is that there are two processes and one common buffer of information. One process fills the buffer, and the other takes information from there. As I understand it, you need to use fork (). If the buffer is empty, then you cannot take the information, and if it is full, then you cannot fill it.
I figured out fork (), when we call this method, we duplicate the entire process after it. One is performed by the father and the other by the son. Now, when I write, the father is always executed first, and then the son. How can I make them work at the same time? Well, or alternated randomly and not 1010101010 (1 - father, 0 - son)
Answer the question
In order to leave comments, you need to log in
It feels like you are trying to come up with your pipeline (pipe). Perhaps I misunderstood you, but I think that the easiest way is for you to have two programs:
1. Producer, generates some data in stdout
2. Consumer, receives data from stdin
And run them like this:Producer | Consumer
In the Producer program, after the fork() call, it is not the Consumer part that goes on, but the Producer part. And the forked process immediately calls exec( Consumer ) and can exit safely.
if you write in the windows command line like:
, it will actually be what you want
there is a dir process, it writes to the "buffer" stdout
there is a find process, it writes from the "buffer" stdin
sdtout dir is connected to the stdin find pipe.
In short, read what a pipe is (better in Unix)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question