How to send a string through a pipe

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 มิ.ย. 2020
  • Check out our Discord server: / discord

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

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

    Great stuff and hard-to-find content, thanks!

  • @faithfullyfactual

    Watched this in 2023 and was super helpful. For the task in this video, what I did in my practice was to cast the string pointer (char *) to an unsigned long(which would be the numerical value for the string's starting byte), write that number to the pipe, read the number in the parent, cast it back to a char * and then print the string using %s. This way, I never used strlen because I didn't need to calculate the length of the string. Also, I maintained only one array and didn't have to create another in the parent. It works, is a lot shorter and I also think would execute faster. Thought to share this, but honestly, the unix Processes playlist has taught me a whole lot of things. Thank you!

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

    I likes how the code is so structured and clean . awesome content thanks a lot

  • @vineelkakara6944
    @vineelkakara6944 3 ปีที่แล้ว

    Excellent man...Thanks for this video...

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

    Small error:

  • @TAN-ob9xm
    @TAN-ob9xm 3 ปีที่แล้ว

    Great video thanks man , you''re AWESOME :)

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

    My solution was to set a fixed number of bytes to be written/read on each end (lets say 100 bytes), and all messages are sent and read in 100 bytes. If needed the writing process can loop through and write as many 100 byte strings as needed and at the end it write a escape sequence string ("STOP"). The reading process loops through reading 100 byte strings until it sees the "STOP". This solution allows for variable length messages and the fixed message width may be adjusted during compilation.

  • @master2768
    @master2768 2 ปีที่แล้ว

    Thank You ! =)

  • @JYSERroshanseeam
    @JYSERroshanseeam 3 ปีที่แล้ว

    This is AWESOME!!!!!!!!!

  • @zeelkhokhariya6264
    @zeelkhokhariya6264 2 ปีที่แล้ว

    Great stuff! Just a question how you would do if we want to continuously write and read between child and parent

  • @Luca-ts8dq
    @Luca-ts8dq ปีที่แล้ว

    Highest appreciation for both your course contents and your crisp and straight forward style. I was wondering why don't you just send the address of the first character through the pipe (write(fd[1], &str, sizeof(char *))? Being the string already 0\ terminated this should be enough to resume the complete information in the parent process and would not require to send the length of bytes, don't you think? Thank You for your brilliant work again and to keep it up at this excellent level.

  • @Alex23_12
    @Alex23_12 4 ปีที่แล้ว

    Hi! Awesome video! Thank you so much for that! But, I'll have operating systems exam next week; I must complete the last part of my project: so, I'd like to ask you: what is the code to write numbers (so, INT) in the pipe?! I've tried to do the casting (from int to string very similar to your example), but at the end of the program, I just can see a bytes stream printed on my screen; Please, could you help me?! Thaaaanks! :)

  • @zyghom
    @zyghom 2 ปีที่แล้ว

    before watching it I was 99.99% sure that sending string will end up with the same approach as sending arrays - string in C is ... an array ;-)

  • @user-ct3kl7zf6w
    @user-ct3kl7zf6w 2 ปีที่แล้ว

    heyy, I've just found a small issue, that we better don't use strlen() function for one int multiple times (you did it in child process), cause if we would have big data it could make our program work slower. instead of it, we could initialize int n after fgets() function, then assign value of n to strlen(str). thus, instead of using strlen() function to find a position of '\0', we could directly use type str[n] = '\0'. please confirm if you are agree with this suggestion. watching your videos for three days and already like it:) that's the good stuff, man!

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

    Thank you for the great content!

  • @helmi2376
    @helmi2376 2 ปีที่แล้ว

    In the read and write functions.

  • @ansismaleckis1296
    @ansismaleckis1296 2 ปีที่แล้ว

    How would you go about sending a struct over a pipe? Lets say that the struct contains a variable lenght strings and arrays.

  • @iliaskaleridis6616
    @iliaskaleridis6616 3 ปีที่แล้ว +1

    what if we just read sizeof(char) * 200 since we know we can only get 200 characters from the fgets?

  • @caiomazzaferroadami

    If both char buffers have the same size, why not writing (in the child) and reading (in the parent) the whole string with the null character instead of writing the lenght first? I mean, even if there is trash value after the null character, printf will not display it. I tested it and it worked.

  • @mohammedzuhairahmed6474
    @mohammedzuhairahmed6474 3 ปีที่แล้ว +1

    Hello sir