No video

Communicating between processes (using pipes) in C

  Рет қаралды 272,781

CodeVault

CodeVault

Күн бұрын

Check out our Discord server: / discord

Пікірлер: 325
@jayshah8843
@jayshah8843 4 жыл бұрын
why you don't use wait in parent process(else part) because both process are running parallel
@CodeVault
@CodeVault 4 жыл бұрын
You're right, I think a wait(NULL) is missing at the end of the else part. Although, since, we're writing from the child process to the parent, the program will work properly albeit with some resource leaks. I'm glad you actually noticed my mistake. Good job!
@lxw5231
@lxw5231 4 жыл бұрын
I dont understand, why there is resource leak without wait(NULL)?
@AyushAnshul
@AyushAnshul 4 жыл бұрын
@@CodeVault Why doesn't parent end while we are waiting for input in child?
@Jason-lb1lu
@Jason-lb1lu 3 жыл бұрын
@@lxw5231 because the parent might finish before the child process, which will result in the child process becoming a zombie process, ie its data is not cleared by the time you program ends, taking up space in your system while doing nothing hence a zombie process
@josephmasinre1840
@josephmasinre1840 3 жыл бұрын
@@CodeVault I don't think wait(NULL) is needed, since read is a blocking call, the child will wait until the parent writes into the pipe.
@morpheus7422
@morpheus7422 3 жыл бұрын
Why is channel underrated, I love how you explain just so much.. stuff that took me weeks to grasp just in one video. I wish I found you earlier
@californiacrunchmuffin2918
@californiacrunchmuffin2918 2 жыл бұрын
As a CS student I’ve watched countless tutorials and you are by far one of (if not) the best instructors I’ve come across
@patrickbitzer8350
@patrickbitzer8350 Жыл бұрын
any further recommendations for c? 😇
@californiacrunchmuffin2918
@californiacrunchmuffin2918 Жыл бұрын
@@patrickbitzer8350 Not necessarily C, but for C++ Cherno has really good videos for understanding fundamentals
@nicofernandez865
@nicofernandez865 3 жыл бұрын
dude, all tour videos from the playlist which includes this video have helped a lot in university. thank you so much and keep it up!
@sampapap1188
@sampapap1188 2 жыл бұрын
No word can describe how much your videos helped me take my C a step fourther. Thank youuu 🙏❤
@SlowedOutOfExistence
@SlowedOutOfExistence 3 жыл бұрын
you're a legend you should be proud
@shawnl1155
@shawnl1155 2 жыл бұрын
Wow, this is the most clear and concise coding lessons I have found on youtube. Perfect pace, audio and video quality is great, everything clear. Thank you so much. I was thinking of dropping my university OS course but now I think I may be able to pass with your videos.
@chenruzhao6440
@chenruzhao6440 3 жыл бұрын
Thank you so much for making and posting the Unix Processes in C series of videos, it helps me a lot !!!
@ryoma8402
@ryoma8402 4 жыл бұрын
Your videos are excellent. Really helpful to all IT students out there. Short and straight to the point. And since they explain the basics of every subject so well the rest of the studying is easily done. Keep up the good work.
@johndoesson
@johndoesson 3 жыл бұрын
I've been watching your videos, like how you take the time to explain things which might not always be so obvious. You are the only one who has (good) tutorials on IPC, coulnd't find any other, thought I was lucky when I saw you made two videos on IPC but then checked your channel and saw you've not only covered looots of IPC but also have a huge library of videos on C. So surprising due to how little views/subs you have, very underrated. I must ask, I tried to setup the IDE you use, visual studio code and couldn't get it to run a program, tried looking up how to do it but couldn't find anything clear on it for ubuntu, seems rather advanced to set it up so everything works smoothly? Spent the whole day looking for a good IDE, tried Clion, which froze upon loading project and geany which was no better than texteditor imo :/
@CodeVault
@CodeVault 3 жыл бұрын
Thank you! I have a video on how to set it up on Windows, although it should be the exact same setup for Linux. You just hate to point VSCode to gcc instead of mingw. If it's still an issue, you can send me a message over on Discord and I'll send you the exact configurations I have for Linux.
@LamNguyen-jp5vh
@LamNguyen-jp5vh Жыл бұрын
Thank you so much for recording this video! I have an OS class at school and the professor never taught us anything about this. Then he just released a project and I was hopeless until found this video!
@nicholasfoster5065
@nicholasfoster5065 3 жыл бұрын
This video just saved me 2 hours of reading explaining what should be a simple concept. Thank you so much =D
@harshdeepgupta
@harshdeepgupta Жыл бұрын
This is amazing! What my professors never taught, it is explained here so succinctly. Thank you for making this video!
@tomasglavina4166
@tomasglavina4166 2 жыл бұрын
You are amazing and an amazing teacher, the way you explain is so clear and concise. 15 min of your videos is about a month or two of school classes. You deserve AT LEAST 150k subs
@Burak-cr6um
@Burak-cr6um Жыл бұрын
It was really helpful, thank you. A complex concept can only be simplified in this way.
@eylulgunes0289
@eylulgunes0289 2 ай бұрын
youtube's best c narrator 👑👑
@cinematicShorts000
@cinematicShorts000 Жыл бұрын
I haven't understood forks and pipes all semester, but these two videos that you have were very well explained! Thank you so much, I might just pass my exam lol
@JYSERroshanseeam
@JYSERroshanseeam 3 жыл бұрын
Thank you so much, i wish my professors explained this well
@maryreilly5102
@maryreilly5102 3 жыл бұрын
You're an amazing teacher... and cute ha! Thanks for the tutorials!!!!
@CodeVault
@CodeVault 3 жыл бұрын
Wow, thanks! Feel free to join our discord community if you have anything you want to talk about: discord.code-vault.net
@mrtom-a-hawk6732
@mrtom-a-hawk6732 Жыл бұрын
You literally saved my lab grade! Thank you so much for this very clear tutorial!
@deli5777
@deli5777 Жыл бұрын
Thanks! I spend hours trying to figure out my problem before finding this video and fixed with a few minutes of starting
@abhinavsharma1075
@abhinavsharma1075 Жыл бұрын
Not all heroes wear capes...Some make useful tutorial tooo ... thanx buddy!!!
@habibhasanshakil9086
@habibhasanshakil9086 2 жыл бұрын
Awesome videos no doubt. This playlist is the lifeline of my OS labs this semester. I have one suggestion for you; it would be better if you use an online board and some diagrams when explaining codes. Though I understood most of the explanations, I recommended this playlist to one of my friends and he didn't understand many things. not everyone has good imagination skills. Subscribed your channel. God bless you.
@CodeVault
@CodeVault 2 жыл бұрын
Thanks for the suggestion! I will keep it in mind for the future videos
@abbashaider7165
@abbashaider7165 Жыл бұрын
You have clear concepts with nice articulating skills. Thankyou :)
@sergi9405
@sergi9405 2 ай бұрын
00:00 - Introduction to inter-process communication and the purpose of the video. 01:20 - Explanation of pipes as a method of inter-process communication. 02:40 - Basic syntax and functions for creating pipes in C. 04:15 - Demonstration of creating a pipe in C with a simple example. 06:00 - Discussion of reading from and writing to pipes. 07:30 - Example of parent-child process communication using pipes. 10:00 - Handling errors and closing pipes. 12:00 - Summary and conclusion.
@moizcrafts3893
@moizcrafts3893 3 ай бұрын
this seem to me impossible while studying in uni,but now u have explained it really good
@blazkowicz666
@blazkowicz666 3 жыл бұрын
You're doing God's work 🙏🙏 💯
@coreytodtaylor
@coreytodtaylor 2 ай бұрын
Hey! I like your videos! The only thing I suppose was wrong in that one is that your doesn't close the descriptor in case of write or read error and return straight away
@dr-mee
@dr-mee 3 жыл бұрын
You are legend man.
@Alpha-ng6oc
@Alpha-ng6oc 2 жыл бұрын
You're explaining that very clearly. Thank you, it helped me very much!
@mushroom2493
@mushroom2493 3 ай бұрын
thanks for the video. you saved me. I love you. hope you have a good life :')
@haster6400
@haster6400 2 жыл бұрын
THis is one of the best video that I had liked Thanks you very much
@back81192
@back81192 3 жыл бұрын
Man, you are my savior!
@Yuri-bt4wl
@Yuri-bt4wl Жыл бұрын
You sound just like Shaggy lol Thank you for the lesson!
@aimenigh4413
@aimenigh4413 2 жыл бұрын
Thank you very much sir , you have a very good explication , thanks a lot from Algeria ❤️
@mohansuri2683
@mohansuri2683 2 жыл бұрын
Thanks a ton for this video, This cleared up so many things to me
@aniketpalve6615
@aniketpalve6615 2 жыл бұрын
Good Explanation... Really helps to solve the college assignments solution.
@jeroen3648
@jeroen3648 3 жыл бұрын
Thank you for this tutorial, it helped me understand linux pipe :)
@Squish888
@Squish888 3 жыл бұрын
Your videos are a massive help!
@xinking2644
@xinking2644 Жыл бұрын
thanks for your video! What should I do if I want to get some complex return value like array of class object from child process ?
@CodeVault
@CodeVault Жыл бұрын
Here's a video on how to send an array through pipes: code-vault.net/lesson/phac6gv4cy:1603733529763 It's very similar to how you would send a struct or object
@xinking2644
@xinking2644 Жыл бұрын
@@CodeVault get it , thank you!
@bama2619
@bama2619 3 жыл бұрын
great teaching skills, thank you. Understandable after watching for the first time.))
@murilo_dev
@murilo_dev 5 ай бұрын
Very nice explanation! Thank you very much for your content!
@enkelly7496
@enkelly7496 2 жыл бұрын
Absolutely love this content, thank you!!
@tongpoo8985
@tongpoo8985 2 жыл бұрын
oh thank god you have a video on this
@benwolio9356
@benwolio9356 2 ай бұрын
great lesson hairline man
@isakarahan3037
@isakarahan3037 2 жыл бұрын
You are awesome, I really understood the topic with your explanations. Thanks you so much....
@sarahali6946
@sarahali6946 3 жыл бұрын
thank you this was really helpful and it saved me a lot of time
@kewtomrao
@kewtomrao 3 жыл бұрын
These vids are damn helpful for my OS practical classes.Is there a video where you show how you set up vs code and the debugger for C?I use sublime text now but without debugger.Thanks
@CodeVault
@CodeVault 3 жыл бұрын
This one: code-vault.net/course/yx1g2sh6l4:1610029046575/lesson/4wy66ezt7u:1610303902122 And the next in the playlist shows how to run in on Linux and how I actually run VSCode
@nobi_nose9469
@nobi_nose9469 3 жыл бұрын
you are amazing. thank you for making this video!
@keithdumont
@keithdumont 2 жыл бұрын
Love your videos, thank you!!
@vkatasonov
@vkatasonov 10 ай бұрын
Hello and thx for the video. One thing that confused me a little bit is why do we close fd before making some operation. It seems to be more logical if pipe would read from fd0 and then write to fd1. But looks like it’s two different processes.
@vkatasonov
@vkatasonov 10 ай бұрын
If you close fd in one process in another it will still work?
@CodeVault
@CodeVault 10 ай бұрын
fds are duplicated after you call fork(). So, if you open a pipe() and then fork() you have 4 fds in total. Since from one process we only read and from another we only write we don't need half of them
@oleholgerson3416
@oleholgerson3416 3 жыл бұрын
Thank you for sharing your knowledge, that was very helpful
@fernandoguirao3748
@fernandoguirao3748 2 жыл бұрын
Super clear video! Do you have any extension for VS to show a little explanation of the functions when you have your cursor above?, when I do so it only shows me the prototype of the function
@CodeVault
@CodeVault 2 жыл бұрын
I have the C/C++ extension from Microsoft. It should work but you just have to make sure it's configured correctly (there might be some path you have to add to the headers and whatnot)
@danielmouraJC
@danielmouraJC 2 жыл бұрын
Me too
@kagaskaa2680
@kagaskaa2680 Жыл бұрын
​@@CodeVault can u please elaborate because installing the extension is easy but I have no idea how to configure it, as a beginner this information pop-up can help us a lot!
@danielmouraJC
@danielmouraJC Жыл бұрын
@@CodeVault I haven't been able to
@pachu242424
@pachu242424 3 жыл бұрын
Clear information. Great! This things are hard to Find on this kind of topics. Thank you and here is your like and subscribe from Argentina
@jonathanazzopardipaul5048
@jonathanazzopardipaul5048 3 жыл бұрын
Great video, understand pipes now. Cheers!
@gustavoalexguardiaguardia5790
@gustavoalexguardiaguardia5790 9 ай бұрын
quality content! What book would you recommend reading about operating system?
@CodeVault
@CodeVault 7 ай бұрын
Just the up-to-date manual on any operating system has enough information. Books could be outdated and I never really look into them
@StackMemory0x00
@StackMemory0x00 2 ай бұрын
The best book you could ever read about programming and OS is Computer Science from bottom up for Ian Wienand. Its a great book by all means. You will never regret any minutes spent reading. I wish if I found this book years ago.
@vanchark
@vanchark 5 ай бұрын
I came here for 6:54. I was wondering why in my professor's sample code you have to close the other end of the pipe. Turns out it's very simple -- it's because we inherit it but we're not using it haha
@timog7358
@timog7358 11 ай бұрын
fantastic video
@enesb4797
@enesb4797 2 жыл бұрын
you are the best
@caloc5028
@caloc5028 Ай бұрын
hey, how can you see the documentation for the function, i have VS code and C/C++ extension ,but i dont have the mehod documentations
@vedhvijay5602
@vedhvijay5602 2 жыл бұрын
Very well explained! Thank you!
@hrishikeshp856
@hrishikeshp856 3 жыл бұрын
This video was quite helpful!
@hackedyou116
@hackedyou116 10 ай бұрын
@CodeVault , why cant we use a global valiable in that program declared before fork() and just store the input value in that variable?
@CodeVault
@CodeVault 10 ай бұрын
Because global variables are only global to the process. Each process (child and parent process) get their own set of global variables. Modifying one global variable in one process won't change it in the other
@ahmedf2
@ahmedf2 2 жыл бұрын
Thanks a lot for the wonderful video, I have a question, why do we need to communicate between processes?
@CodeVault
@CodeVault 2 жыл бұрын
There are a lot of reasons. Think about all the tools you're using on your computer and what happens when you do something that makes them interact. Something like, drag and dropping an image from a process to another Other reasons could be to reuse functionality. If you have a program and you want to count the number of words in some text you could reuse the program "wc" and simply put a pipe between your process and the "wc" process' stdin and stdout
@ahmedf2
@ahmedf2 2 жыл бұрын
@@CodeVault Thanks a lot my friend, by the way what's your name?
@exeprinced
@exeprinced 2 жыл бұрын
Excellent tutorial. Thanks a lot.
@yogi3058
@yogi3058 2 жыл бұрын
Explanation is good but there is correction here. Else part is parent part of process because fork return number is non zero for Parent process only.
@CodeVault
@CodeVault 2 жыл бұрын
I'm pretty sure that's how it was set up. Do I say in the video otherwise?
@joanbo2346
@joanbo2346 4 жыл бұрын
Really helpfull explanation and example. Many thanks dude :D
@pedrooriakhi6206
@pedrooriakhi6206 2 жыл бұрын
Thank you soo much man.
@kiseijuu7420
@kiseijuu7420 5 ай бұрын
I have multiple question. Why u dont wait at the end of the parent? Since u dont wait, why did the child process always run before the parent? For exemple why u didnt get an error telling u that value y isnt initialised cause we learned that u never know which process execute first if u dont wait. Second, how did u open the fd? Dont u need to use open() after using a pipe? Cause pipe juste gives u fd, but they dont actually open them right? + dont u need to give them the permission to either read or write in them? And last question, since u use a protection for ur fork, ur write and ur read, why didnt u close the fd before returning each error value? Cause what i see here is that if u fail to write, then u return 2 if i remember correctly, and only fd[0] is closed, while fd[1] remains open no? Except from these questions, i find ur videos really helpful thanks 🙏 , cause i noticed that since the beginning i only ask questions without thanking u lol 😂, sry about that.
@CodeVault
@CodeVault 4 ай бұрын
1) read() always waits for there to be something written to the pipe 2) pipe() already opens the fds so no open() call is needed 3) You're correct. The better solution would be to close the fds before returning. But, since we are returning, the OS will automatically close the fds for us. It's just good practice to close them but not required. It's also a good idea to close them once you don't need them anymore if it's a long-running process
@hiotasmusic3811
@hiotasmusic3811 Жыл бұрын
Hi, what is your VSCode extension which shows you the function's description ? Thank you !
@CodeVault
@CodeVault Жыл бұрын
It's the C/C++ extension from Microsoft. Make sure the headers are configured properly otherwise it won't show the tooltips properly
@hiotasmusic3811
@hiotasmusic3811 Жыл бұрын
@@CodeVault ok I see, thank you ! Your videos help me a lot !
@jamshidbek2000
@jamshidbek2000 Жыл бұрын
Thanks for the explanation. QUESTION : if there is an error when you either read or write and return the program, Will the file descriptors be left open?
@CodeVault
@CodeVault Жыл бұрын
Once the program finsihes execution, the operating system should automatically close those file descriptors
@jamshidbek2000
@jamshidbek2000 Жыл бұрын
@@CodeVault Thank you =)
@pablo17349
@pablo17349 2 жыл бұрын
Please share your keyboard model, it sounds delicious!
@CodeVault
@CodeVault 2 жыл бұрын
Corsair K65 with red switches I use in that video, although I don't really recommend it. Nowadays I use a Das Keyboard with brown switches. Much easier to type on
@sakkamouid3343
@sakkamouid3343 Жыл бұрын
Okay in 8:40 , let's suppose you have corrected the code there as said by someone from the comments by adding wait(NULL) in the else block to make the parent wait for the child and executed it. One thing confuses me : how could you read from fd[0] in line 27 when you have closed that buffer in line 18? I am not used to use the function close. Any explanation for my confusion?
@CodeVault
@CodeVault Жыл бұрын
First things first: when we create a pipe using pipe(fd) we are getting in return 2 file descriptors. Now, something interesting happens when we call fork(): all the opened file descriptors of the process we are forking get duplicated (including our pipe's file descriptors). At the end of the fork() call we are left with 4 file descriptors, 2 for each process. We only close two of them: one read end in the child process and one write end in the parent process. This means we can still use the write end on our child process and the read end on our parent process. And that's exactly what we do. Hope this cleared up the confusion
@user-ti3qt9ik1d
@user-ti3qt9ik1d Жыл бұрын
thank's!! It was really clear🙏
@baranklc6302
@baranklc6302 11 ай бұрын
I have a question sir. Why we have to fork right after the pipe? Can't we just pipe first after fork? What is the difference? Apart from sir, everyone who knows the exact answer shall comment under my question too, i really welcome your thoughts. Thank you in advance
@CodeVault
@CodeVault 10 ай бұрын
pipe() created a pair of file descriptors (basically IDs). If you first fork() and then pipe() you will be left with two different pipes (since pipe() would be called on both processes) and, since the file descriptors would be different you wouldn't be able to communicate between them
@vaibhavpanvalkar3025
@vaibhavpanvalkar3025 2 жыл бұрын
@CodeVault has real value
@toniiicarbonelll287
@toniiicarbonelll287 3 жыл бұрын
excellent, thank you very much for you work
@justintang9801
@justintang9801 22 күн бұрын
ive been running the code using on VS code using a mac but the child process has been executing first, printing "Got from child process ..... then Input a number
@anzu8698
@anzu8698 2 жыл бұрын
Amazing, thank you so much!
@PetraTToth
@PetraTToth 3 жыл бұрын
what program do you use to run the code? we programmed c in codeblocks, but that obviously can't run these types of codes and i tried putty, but it's just problematic. also thank you so much for these videos, you're the reason i haven't failed yet in my operation system class.
@CodeVault
@CodeVault 3 жыл бұрын
Glad to be of help. There's this video and the next one in the list presenting how to use VSCode in Linux and how I am using VSCode to run the programs (it's a bit more complex): code-vault.net/course/yx1g2sh6l4:1610029046575/lesson/4wy66ezt7u:1610303902122
@vivekkumarverma685
@vivekkumarverma685 2 жыл бұрын
Well explained... Simply amazing 🤩
@anton78570
@anton78570 2 жыл бұрын
thank you so much! very clear explications!
@alternativeenergyresearch4857
@alternativeenergyresearch4857 4 жыл бұрын
Make video on how to make Excel as dde server so that every second data in Excel may be poke out to trading platform or charting software
@djoykeabyah5904
@djoykeabyah5904 Жыл бұрын
Thank you so much for this video! I'm only a bit confused because while following along with the code around 11 min in the video my output showed only 2 printf messages or just one when we removed the break. ➜ ./a.out wrote 8 result is 8 Why is that happening? does that mean that even with the break the parent process is too quick for the child even to give any form of output?
@CodeVault
@CodeVault Жыл бұрын
I'm guessing your program just never waits for the child process to finish its execution. Try adding a wait(NULL) before the return of the parent process
@djoykeabyah5904
@djoykeabyah5904 Жыл бұрын
@@CodeVault thanks! I'll try that out!
@nostolgiagore
@nostolgiagore 8 күн бұрын
Dose this have to written in main?
@ihoussem3367
@ihoussem3367 4 жыл бұрын
Simple explanation! Thanks again
@tii04
@tii04 2 жыл бұрын
I may have missed the answer to this while I was skimming through the chat, but I'm curious to know why when I enter a string instead of a number as input for the child, a number is still returned?? Is this number a process id?? If so is it a process Id of the child or the parent??
@CodeVault
@CodeVault Жыл бұрын
Everything is a number in C. Strings are just a set of numbers that are converted to characters using the ASCII table. Most likely, what you received there was either the address of the first character of the string or the character itself (the ASCII value of it)
@flamendless
@flamendless 3 жыл бұрын
Awesome thanks a lot! Please need some guidance on how to get the output of printf of another program (child) then receive that in the main program (parent) but not after the child is closed or done?
@CodeVault
@CodeVault 3 жыл бұрын
There's this video on the topic: code-vault.net/lesson/43zvcsz6o1:1603732432539
@themodesttraveler745
@themodesttraveler745 2 жыл бұрын
i have been watching you videos and there are very good . but im trying to use system(); to call nmap and mysql togther and feed one with inforamtion with the other .do you have any videos on piping console output and input
@CodeVault
@CodeVault 2 жыл бұрын
Yes, there's this video: code-vault.net/lesson/43zvcsz6o1:1603732432539
@0xdjav
@0xdjav 2 жыл бұрын
Hello, Thanks for these usefull videos! I was wondering how you can see on VS the definitions of functions that you call, for instance pipe : "Create a one-way communication channel [...] " Thanks for the help :) best
@CodeVault
@CodeVault 2 жыл бұрын
I just installed the C/C++ extension from Microsoft and made sure it pointed to the right folder where the compiler is
@dopetag
@dopetag 7 ай бұрын
Why no wait() in the parent though? Does the parent wait by default till the user inputs something in scanf? Why does it work? That is confusing..
@CodeVault
@CodeVault 7 ай бұрын
read() automatically waits for something to exist in the pipe to be read. Similarly write() also waits for space in the pipe's buffer
@mahmudhassan6624
@mahmudhassan6624 9 ай бұрын
In this case, the parent process would try to read first, before the child process writes. Surprisingly, the code still works without wait() in the first line of else block. How does this work?
@CodeVault
@CodeVault 9 ай бұрын
The read call always waits for some data to exist in the pipe's buffer
@NOPerative
@NOPerative 3 жыл бұрын
Excellent video.
@naseerahmed3162
@naseerahmed3162 3 жыл бұрын
Hi , Do you have to wait i the else part at the begenning of paper before reading from the pipe(fd[0]) for the child to write to fd[1] and finish its execution basically i was asking if you can a write call before anything is written to the pipe. please advices
@CodeVault
@CodeVault 3 жыл бұрын
No you don't. read will wait for there to be something in the pipe, similarly write will wait for there to be space in the pipe's buffer.
@patrickbitzer8350
@patrickbitzer8350 Жыл бұрын
what would happen if the user inputs -1? in this case wouldnt the if-statement return an error? if yes how could I deal with this unwanted behavior?
@CodeVault
@CodeVault Жыл бұрын
No, it won't return an error. The if statement relates to the return value of the read call (not what we actually read from the pipe). The read call will still return a positive number while we will have -1 in the y variable
@dealvin
@dealvin 2 жыл бұрын
do you have some videos about mmap() function?. Thanks for this video.
@CodeVault
@CodeVault 2 жыл бұрын
No yet
@raulpetcu9202
@raulpetcu9202 2 жыл бұрын
thank you very much :)
@HedgehogShimmered
@HedgehogShimmered 3 жыл бұрын
Just a question , shouldn't you put an exit a then end of your child? Because if you make a wait(null) in your father process it might be stuck forever if the child never dies?
@CodeVault
@CodeVault 3 жыл бұрын
I'm actually indirectly calling exit here. There's one more line of code executed after the if block, that is the 'return 0;'. Which is equivalent to 'exit(0);' if done in the main function.
@17Kpa
@17Kpa Жыл бұрын
Help me with this exercise please I don't understand how to do it 2) Write a program that receives a variable number of filenames from the command line. commands. For each file name the program must create a child process that: - Print your PGID, PPID, PID and file name; Y - Use one of the exec() family functions to execute: wc -l file_name. Considerations: - Child processes must be executed concurrently. - The parent process must indicate which child process is ending and indicating what way ends (Normal or by a signal). - If no filename is passed an error message should be displayed. - The system() system call cannot be used.
@CodeVault
@CodeVault Жыл бұрын
There are a few videos that can help with this exercise: code-vault.net/course/46qpfr4tkz:1603732431896/lesson/as15alvu0a:1603732432433 code-vault.net/course/46qpfr4tkz:1603732431896/lesson/oxyoxbvnak:1603732432935
@17Kpa
@17Kpa Жыл бұрын
@@CodeVault Thank you! managed to solve.
@husseinmahmoud6833
@husseinmahmoud6833 2 жыл бұрын
First of all thanks for the video, but I don't understand what happens when we return a number to exit a thread (ex: return 1 when an error occurs in opening the pipe). Does this number have a meaning or its printed on console window to indicate the part of the error or something like that?
@CodeVault
@CodeVault 2 жыл бұрын
No, it has no meaning. The only important thing is that it's not 0, thus considered an error by the OS. When I run it and get an error, I also will get an error code, which is the return value from the main (that 1 that you're talking about). Me, the programmer, seeing that 1, I can tell that something went wrong with opening the pipes and it's not just some random error. That's how these are used
Iterating over neighbours in a multi-dimensional array in C
12:36
Practical use case for fork and pipe in C
12:52
CodeVault
Рет қаралды 77 М.
Schoolboy Runaway в реальной жизни🤣@onLI_gAmeS
00:31
МишАня
Рет қаралды 3,3 МЛН
Pool Bed Prank By My Grandpa 😂 #funny
00:47
SKITS
Рет қаралды 19 МЛН
Harley Quinn's revenge plan!!!#Harley Quinn #joker
00:59
Harley Quinn with the Joker
Рет қаралды 26 МЛН
managed to catch #tiktok
00:16
Анастасия Тарасова
Рет қаралды 42 МЛН
Two way communication between processes (using pipes) in C
18:16
Working with multiple pipes
19:38
CodeVault
Рет қаралды 54 М.
Unix Pipeline (Brian Kernighan) - Computerphile
5:16
Computerphile
Рет қаралды 216 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,5 МЛН
Calling fork multiple times
13:58
CodeVault
Рет қаралды 108 М.
Object Oriented Programming vs Functional Programming
18:55
Continuous Delivery
Рет қаралды 752 М.
Introduction to FIFOs (aka named pipes) in C
18:49
CodeVault
Рет қаралды 83 М.
Simulating the pipe "|" operator in C
19:52
CodeVault
Рет қаралды 82 М.
Process IDs in C
10:14
CodeVault
Рет қаралды 90 М.
Sending and Handling Signals in C (kill, signal, sigaction)
5:52
Jacob Sorber
Рет қаралды 186 М.
Schoolboy Runaway в реальной жизни🤣@onLI_gAmeS
00:31
МишАня
Рет қаралды 3,3 МЛН