I am looking at the code for a C ++ program that loads the contents of the file more. I donβt quite understand this, so I was wondering if anyone can write pseudo-code for C ++ - a program that passes something else? Why is fork necessary?
create pipe fork process if child: connect pipe to stdin exec more write to pipe
You need fork()to be able to replace the stdin of the child before the call and not wait for the process to complete.
fork()
You will find your answer exactly here.
fork?
, .
$ ls | more
? ( ls, more). , (STDOUT) ls (STDIN) more, .
ls
more
, ls more , ( ) STDOUT ( STDIN) . , , , , , . ls , more - .
... - - ...
, concurrency, - (, more), . , fork. more ( exec), .
fork
exec
, fork, . , (, ), .