Dude, i think you forgot to use the close function. On the the father, before writing you should close the read file descriptor of the father. After writing, you should also close the write descriptor of the father. This tells to the kernel that the father does not need to listen or write anymore, saving resources. Also, you should close the the write file descriptor of the child process before reading, and close the read file descriptor after finishing.
Pipe is an example of a Linux system call which is a service that the operating system provides that applications can call, for example there are also system calls for opening files and writing to files and much more. Check out my video about Linux System Calls for a more basic example.
I imagine the pipe as a file in which I can write into via fd[1] and I can get stuff out of with fd[0]. In the diagram at the beginning of this video, the first hello on the left is going into the pipe via fd[0] and the second one coming out of the pipe via fd[0]. I hope that's correct. btw: why did you open the pipe before creating the fork? I understand that both will have the same copy of fd array (at different memory space), but why not declaring fd afterwards?
question : what happens when the parent process dies first? does it not create a zombie process? and if so how did the program work after killing the parent process? thank you for the content sir keep it up!
yes the process will be a zombie process and it will have its ppid set to init system's pid. I think SIGKILL won't affect it and resources are not returned until the process is finished.
it just has a steep learning curve compared to other editors, but once you get used to it you'll never want to go back. at least not to regular keybindings. Like, if I'm one day forced to use something like vscode for work, I'll definitely install the vim keybindings extension. Now that I know how to use vim, I don't ever want to go back to writing text the normal way. It's just extremely slow. You should definitely give it a shot. Trust me, if you stick with it for even a few days, you'll already be competent enough to never want to go back.
it wouldn't, windows isn't POSIX-compliant. Nir is on windows here but he's doing all that on wsl, so he still gets that POSIX functionality. If you want to do this natively on windows, the code would look a lot different and you'd be using the windows api, not the C standard library, since it's built specifically with POSIX in mind.
You summarized my 4 two-hour operating system classes in 4 minutes. Thanks
Stumbling upon your channel is one of the greatest things that happened to me in 2023. Keep up the great work!
Also, can you do one on grep? XD
Thanks :)
Yes, grep is a good idea, very powerful and useful command
Dude, i think you forgot to use the close function. On the the father, before writing you should close the read file descriptor of the father. After writing, you should also close the write descriptor of the father. This tells to the kernel that the father does not need to listen or write anymore, saving resources.
Also, you should close the the write file descriptor of the child process before reading, and close the read file descriptor after finishing.
mind blown, hopefully one day I'll actually understand stuff like this
Pipe is an example of a Linux system call which is a service that the operating system provides that applications can call, for example there are also system calls for opening files and writing to files and much more. Check out my video about Linux System Calls for a more basic example.
@@nirlichtman oh, I mostly understand that part
it's the actual low-level magic in the code I don't get
@@phatboislym what specific part of the code? I can help explain
I imagine the pipe as a file in which I can write into via fd[1] and I can get stuff out of with fd[0]. In the diagram at the beginning of this video, the first hello on the left is going into the pipe via fd[0] and the second one coming out of the pipe via fd[0]. I hope that's correct.
btw: why did you open the pipe before creating the fork? I understand that both will have the same copy of fd array (at different memory space), but why not declaring fd afterwards?
Well, I thought I know pipes. Almost didn't watch the video. Turns out I didn't
question : what happens when the parent process dies first? does it not create a zombie process? and if so how did the program work after killing the parent process?
thank you for the content sir keep it up!
yes the process will be a zombie process and it will have its ppid set to init system's pid. I think SIGKILL won't affect it and resources are not returned until the process is finished.
thank u @@abzrg , i eventually got the exact same answer, thank u again
After line 12, when the parent and child split and after return, is it possible to get back to the parent process?
your content is just amazing!
=
writing code in vim is so difficult - big respect
it just has a steep learning curve compared to other editors, but once you get used to it you'll never want to go back. at least not to regular keybindings.
Like, if I'm one day forced to use something like vscode for work, I'll definitely install the vim keybindings extension. Now that I know how to use vim, I don't ever want to go back to writing text the normal way. It's just extremely slow.
You should definitely give it a shot. Trust me, if you stick with it for even a few days, you'll already be competent enough to never want to go back.
I'm watching these videos in the background while I do other things lol
Amazing explanation in less time 🫡🙏
Sick af. Great explanation.
Perfect explanation!
How would this work on Windows?
it wouldn't, windows isn't POSIX-compliant. Nir is on windows here but he's doing all that on wsl, so he still gets that POSIX functionality. If you want to do this natively on windows, the code would look a lot different and you'd be using the windows api, not the C standard library, since it's built specifically with POSIX in mind.
💖💖💖💖
i see.
This made no sense 😹