Linux Pipes Explained in 3 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2024

ความคิดเห็น • 26

  • @dvoraklovelace2801
    @dvoraklovelace2801 ปีที่แล้ว +52

    You summarized my 4 two-hour operating system classes in 4 minutes. Thanks

  • @lucasschneider-dev
    @lucasschneider-dev ปีที่แล้ว +14

    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

    • @nirlichtman
      @nirlichtman  ปีที่แล้ว +4

      Thanks :)
      Yes, grep is a good idea, very powerful and useful command

  • @thiagoalexandrenakao9071
    @thiagoalexandrenakao9071 17 วันที่ผ่านมา +1

    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.

  • @phatboislym
    @phatboislym ปีที่แล้ว +6

    mind blown, hopefully one day I'll actually understand stuff like this

    • @nirlichtman
      @nirlichtman  ปีที่แล้ว +5

      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.

    • @phatboislym
      @phatboislym ปีที่แล้ว

      @@nirlichtman oh, I mostly understand that part
      it's the actual low-level magic in the code I don't get

    • @nirlichtman
      @nirlichtman  ปีที่แล้ว

      @@phatboislym what specific part of the code? I can help explain

  • @abzrg
    @abzrg 4 หลายเดือนก่อน +2

    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?

  • @tankman1301
    @tankman1301 ปีที่แล้ว +2

    Well, I thought I know pipes. Almost didn't watch the video. Turns out I didn't

  • @yaSSeraitnaSSer
    @yaSSeraitnaSSer 6 หลายเดือนก่อน +1

    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!

    • @abzrg
      @abzrg 4 หลายเดือนก่อน +2

      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.

    • @yaSSeraitnaSSer
      @yaSSeraitnaSSer 4 หลายเดือนก่อน

      thank u @@abzrg , i eventually got the exact same answer, thank u again

  • @Jonathan-ru9zl
    @Jonathan-ru9zl 4 หลายเดือนก่อน

    After line 12, when the parent and child split and after return, is it possible to get back to the parent process?

  • @pandorian7
    @pandorian7 9 หลายเดือนก่อน +1

    your content is just amazing!
    =

  • @DragonSlayer22740
    @DragonSlayer22740 6 หลายเดือนก่อน

    writing code in vim is so difficult - big respect

    • @not_kode_kun
      @not_kode_kun 3 หลายเดือนก่อน +2

      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.

  • @Bearded_Dragon_Sir
    @Bearded_Dragon_Sir ปีที่แล้ว

    I'm watching these videos in the background while I do other things lol

  • @navdeepladdha1775
    @navdeepladdha1775 2 หลายเดือนก่อน

    Amazing explanation in less time 🫡🙏

  • @joehayden6065
    @joehayden6065 4 หลายเดือนก่อน

    Sick af. Great explanation.

  • @cheesus2289
    @cheesus2289 10 หลายเดือนก่อน

    Perfect explanation!

  • @jasdfff770
    @jasdfff770 7 หลายเดือนก่อน

    How would this work on Windows?

    • @not_kode_kun
      @not_kode_kun 3 หลายเดือนก่อน

      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.

  • @ChandrashekarCN
    @ChandrashekarCN หลายเดือนก่อน

    💖💖💖💖

  • @DecoyBBQCam
    @DecoyBBQCam ปีที่แล้ว

    i see.

  • @Cheeseson
    @Cheeseson 7 หลายเดือนก่อน

    This made no sense 😹