@@tashian Why wouldn't the computer just reserve memory for the program and then run it? What if you were running a big process and need to call a simple one? It's going to copy the whole process first? That seems wasteful.
@@sweetness583 It's a great question. Forking a process is efficient and requires very few resources, due to the way memory management works on most computers. Look up "copy-on-write memory management" for more details.
do parent and child processes both write to the same fd1,fd2 concurrently? sorry, not an expert here. let me ask that little differently after exec() and replacing current shell program with some other program like echo with args "foo" echo writes $1 to stdout. so do I start to see "foo" getting displayed on terminal right here even before child exits?
Yeah! Try it and see. Both programs will have the same fd0, 1, and 2. One thing bash handles is redirection, by modifying the file descriptors for the child before exec() is called.
Underrated in terms of likes. Really worth it for all the details you shared flawlessly.
great video !! thanks a lot for posting this
Amazing video ! Can you please tell me what terminal is this that you are using?
Nice. Thank you!!
Why does fork() create a copy of the currently running process? That seems unnecessary.
What do you mean by unnecessary?
@@tashian Why wouldn't the computer just reserve memory for the program and then run it? What if you were running a big process and need to call a simple one? It's going to copy the whole process first? That seems wasteful.
@@sweetness583 It's a great question. Forking a process is efficient and requires very few resources, due to the way memory management works on most computers. Look up "copy-on-write memory management" for more details.
@@tashian Oh ok. Thanks, I will look that up.
do parent and child processes both write to the same fd1,fd2 concurrently?
sorry, not an expert here. let me ask that little differently
after exec() and replacing current shell program with some other program like echo with args "foo"
echo writes $1 to stdout. so do I start to see "foo" getting displayed on terminal right here even before child exits?
Yeah! Try it and see. Both programs will have the same fd0, 1, and 2. One thing bash handles is redirection, by modifying the file descriptors for the child before exec() is called.
ah aha ah aha aha ahahahahahaahha