Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How multiple process are able to use STDIN/STDOUT simultaneously?

How can multiple process access STDIN,STDOUT at the same time. And each of them has its own instances running independently without causing problem in other process i/o ?

like image 754
4bh1 Avatar asked Jan 04 '23 20:01

4bh1


2 Answers

STDIN and STDOUT are just aliases for I/O streams. Each process has its own STDIN and STDOUT.

However, it is possible for two processes to have their own STDIN and STDOUT mapped to the same stream. The results are bizarre.

Try running multiple programs in the background that read from and write to the console.

The way the system avoids chaos is through system protection. A normal user cannot run a program from a terminal that reads and writes to someone else's terminal.

But, if you want to screw yourself up by running multiple programs that read from and write to YOUR console/terminal, the system does not protect you from yourself.

like image 179
user3344003 Avatar answered Jan 08 '23 01:01

user3344003


STDIN/STDOUT are nothing but the file descriptors and each process would have its own FD.

Below discussions would beef help for you:

https://unix.stackexchange.com/questions/96724/how-can-a-command-have-more-than-one-output

https://unix.stackexchange.com/questions/31334/what-is-meant-by-connecting-stdout-and-stdin/31339#31339

like image 34
Dipti Shiralkar Avatar answered Jan 08 '23 00:01

Dipti Shiralkar