How to send an array through a pipe

  Рет қаралды 23,018

CodeVault

CodeVault

Күн бұрын

Пікірлер: 40
@samuelokoli6584
@samuelokoli6584 Жыл бұрын
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 10 ай бұрын
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 жыл бұрын
great topic - it's really helpful!
@lucas90gs
@lucas90gs 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 жыл бұрын
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 11 ай бұрын
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
@ayoubmentag9883
@ayoubmentag9883 2 жыл бұрын
Amazing video , thank you :)
@navidnouri151
@navidnouri151 3 жыл бұрын
Thank you!
@RaviSankar-ln3ki
@RaviSankar-ln3ki 3 жыл бұрын
Nice one. 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
@massinissamellikeche6859
@massinissamellikeche6859 21 күн бұрын
I tried to send a matrix from a server to a client with read and write but the client only prints the first line of the matrix, do you have any idea why this happens ?
@venkatesh4760
@venkatesh4760 4 жыл бұрын
@CodeVault Great explanation .. I watch all ur videos..please make your codes in videos available anywhere like Github.
@CodeVault
@CodeVault 4 жыл бұрын
Will do in the near future!
@vladimir_khlghatyan
@vladimir_khlghatyan 2 жыл бұрын
@@CodeVault Have you already done?
@sudhansujena5323
@sudhansujena5323 2 жыл бұрын
How is it possible for fork() to return two values?
@CodeVault
@CodeVault 2 жыл бұрын
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 3 жыл бұрын
does read() know to read from after , what has already been read (here n) ?
@CodeVault
@CodeVault 3 жыл бұрын
Yes. read() waits for data to be written to the pipe
@utksingh7
@utksingh7 3 жыл бұрын
@@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 3 жыл бұрын
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 3 жыл бұрын
@@CodeVault Okay, I get it now. Thanks a lot
@anujajadhav9532
@anujajadhav9532 4 жыл бұрын
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 4 жыл бұрын
You can simply call write twice for those 2 integers you want to pass and read 2 times in the receiving process
@franklinordonez7243
@franklinordonez7243 2 жыл бұрын
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 2 жыл бұрын
Make sure you're passing the sizeof(struct) to the read/write operations
@dragosmarinescu9388
@dragosmarinescu9388 8 ай бұрын
are you romanian?
@CodeVault
@CodeVault 8 ай бұрын
Da
@asifsaad5827
@asifsaad5827 4 жыл бұрын
and why did you close the write end in parents process?
@CodeVault
@CodeVault 4 жыл бұрын
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 3 жыл бұрын
I'm studying at 42 and pretty glad that he's doing all of these explanations in C xD
@theflyingdutchman3942
@theflyingdutchman3942 3 жыл бұрын
@@paulosantana9607 I feel you brother, just started on minishell :D
@prasannapm3220
@prasannapm3220 2 жыл бұрын
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 2 жыл бұрын
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
How to send a string through a pipe
12:09
CodeVault
Рет қаралды 22 М.
Communicating between processes (using pipes) in C
14:00
CodeVault
Рет қаралды 294 М.
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
Introduction to FIFOs (aka named pipes) in C
18:49
CodeVault
Рет қаралды 90 М.
Dear Functional Bros
16:50
CodeAesthetic
Рет қаралды 571 М.
Unix Pipeline (Brian Kernighan) - Computerphile
5:16
Computerphile
Рет қаралды 219 М.
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 942 М.
Working with multiple pipes
19:38
CodeVault
Рет қаралды 56 М.
Two way communication between processes (using pipes) in C
18:16
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 665 М.
Understanding Fork Bombs in 5 Minutes or Less
5:55
Engineer Man
Рет қаралды 176 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 101 М.
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 167 М.