How to send an array through a pipe

Поделиться
HTML-код
  • Опубликовано: 2 июн 2020
  • Check out our Discord server: / discord

Комментарии • 39

  • @samuelokoli6584
    @samuelokoli6584 Год назад +2

    The fact that these videos comes with a great knowledge delivered in the most golden way possible and I still end up gaining even more from the replies to comments and questions below.... man your a kind hero.., Thank you!!.

  • @kerryhuang6953
    @kerryhuang6953 2 месяца назад

    Thank you! I was 6 hours in and wondering why my code doesn't work. Followed your tutorial and it immediately solved my problem.

  • @hectordoyle4718
    @hectordoyle4718 4 года назад +1

    great topic - it's really helpful!

  • @navidnouri151
    @navidnouri151 2 года назад +2

    Thank you!

  • @RaviSankar-ln3ki
    @RaviSankar-ln3ki 2 года назад +1

    Nice one. Thank you.

  • @ayoubmentag9883
    @ayoubmentag9883 Год назад

    Amazing video , thank you :)

  • @zyghom
    @zyghom 2 года назад

    ha, "always send first the number of elements in array" - that is what I got from your another video already but here you explicitly said the same - amazing!
    Question: would pipes work also on embedded systems, i.e. ESP32? I know at the beginning you said: "this is for Linux" but I could find an usage for pipes on microcontroller as well. thx
    Another point: finally I understood why it is so important that array is always "a contiguous block of bytes" - write(fd,arr,n) or read(fd,arr,n) would not work in here if the array was fragmented ;)

    • @CodeVault
      @CodeVault  2 года назад

      Hmm, for embedded it might be different since it doesn't have a notion of processes, it's usually just one big process for the whole thing

  • @venkatesh4760
    @venkatesh4760 3 года назад +1

    @CodeVault Great explanation .. I watch all ur videos..please make your codes in videos available anywhere like Github.

    • @CodeVault
      @CodeVault  3 года назад +1

      Will do in the near future!

    • @video0607
      @video0607 2 года назад

      @@CodeVault Have you already done?

  • @lucassivolella
    @lucassivolella Год назад +2

    Thanks for the videos! A couple of things that are not so clear to me:
    1. When working with pipes, is it guaranteed that the first read on the parent process is going to happen after the first write on the child process, and in turn the second read on the parent process will happen after the second write of the child process?
    2. In this specific program, is adding a wait(null) after the parent first read a good practice, as we know that the child has only one more write to do before finishing its scope, or is it expandable?

    • @CodeVault
      @CodeVault  Год назад +2

      1) Read operations on pipes wait for something to exist in the buffer. So, if the read operation executes first it will wait until something is written to that pipe. Same thing with the write function if there's no space in the pipe's buffer.
      2) You could, but then you can only use the pipe (and the whole child process) only once

  • @ozziekhoo
    @ozziekhoo 4 года назад +3

    Hi Sir, what would be the difference of doing wait(NULL) at the beginning of the parent process, instead of at the end?

    • @raimo7911
      @raimo7911 3 месяца назад

      not much difference, but you wouldn't be taking advantage of parallelism of processes. but again, in this case it's the same because read is going to be on hold until something is written to the write end of the pipe

  • @franklinordonez7243
    @franklinordonez7243 Год назад

    Hi your videos are saving my ass on OS class! I have a question, how do you send an array of structs? I'm trying to do it but sometimes the reader gets incorrect and crazy values, sometimes it reads the values fine. I do not know what is the cause of this problem. :(

    • @CodeVault
      @CodeVault  Год назад +1

      Make sure you're passing the sizeof(struct) to the read/write operations

  • @anujajadhav9532
    @anujajadhav9532 3 года назад

    Sir, how to pass an two integer value for though pipe without rand function and how to calculate the sum of that is integer

    • @CodeVault
      @CodeVault  3 года назад +2

      You can simply call write twice for those 2 integers you want to pass and read 2 times in the receiving process

  • @sudhansujena5323
    @sudhansujena5323 Год назад

    How is it possible for fork() to return two values?

    • @CodeVault
      @CodeVault  Год назад

      It doesn't return two values. It creates a separate copy of the existing process and simply returns different values based on which process it returns to

  • @utksingh7
    @utksingh7 2 года назад

    does read() know to read from after , what has already been read (here n) ?

    • @CodeVault
      @CodeVault  2 года назад +1

      Yes. read() waits for data to be written to the pipe

    • @utksingh7
      @utksingh7 2 года назад

      @@CodeVault thanks for replying, i mean why doesn't read() read from the start of the pipe/file on every call? if we are reading a file and we call read (100 bytes) 2 times then on the first call first 100 bytes will be read and on the second the next 100. How does it know to start reading after the first 100 bytes on the second call?

    • @CodeVault
      @CodeVault  2 года назад +1

      Ahhh, the file descriptor has something called a cursor that remembers where it last finished reading. You can change that with: linux.die.net/man/2/lseek

    • @utksingh7
      @utksingh7 2 года назад

      @@CodeVault Okay, I get it now. Thanks a lot

  • @asifsaad5827
    @asifsaad5827 4 года назад

    and why did you close the write end in parents process?

    • @CodeVault
      @CodeVault  4 года назад +2

      Because the parent process never writes anything on the pipe and pipes are unidirectional.

  • @asifsaad5827
    @asifsaad5827 4 года назад

    why are you not doing your program in cpp?

    • @CodeVault
      @CodeVault  4 года назад

      Well, that's because all the functions we're using in this course are from unix C libraries. So, if people wanted to use C++ for their projects, the same code would work for both.

    • @asifsaad5827
      @asifsaad5827 4 года назад

      @@CodeVault would you mind doing a video on Unix C libraries?

    • @CodeVault
      @CodeVault  4 года назад

      I'll look into it

    • @paulosantana9607
      @paulosantana9607 2 года назад +3

      I'm studying at 42 and pretty glad that he's doing all of these explanations in C
      xD

    • @theflyingdutchman3942
      @theflyingdutchman3942 2 года назад +2

      @@paulosantana9607 I feel you brother, just started on minishell :D

  • @dragosmarinescu9388
    @dragosmarinescu9388 8 дней назад

    are you romanian?

  • @prasannapm3220
    @prasannapm3220 Год назад

    how to read and write to a pipe..... when the date to be written to a pipe is from a filename.txt ?
    // copy the contents from the filename.txt to the pipe
    write(fd[1], &filename.txt, sizeof(char)) ?

    • @CodeVault
      @CodeVault  Год назад +1

      You'd have to probably read/write a string that represents the date in the pipe. There is this video on the topic: code-vault.net/lesson/81boknswet:1603732432887