Students like me pay thousands of dollars to professors who do not even answer emails to help with the homework. Yet, you explained the topic in 10 mins? You are a Hero!!!
This is sooo much better than all those boring powerpoint presentations with people talking like they are zombies. Thank you for making the best content about these topics. Much love!
Thanks to your videos I just passed with the maximum mark a university exam about Unix processes which I failed last summer, I wanted to compliment your teaching way and thank you so much❤️
Worth learning keep making videos Sir. As I had started watching your videos when I was very new to computer science I knew nothing and after completing the C language by seeing your tutorials now I feel confident which definitely going to help me in my career. Thank You Very Much Sir.
I was reading the free ebook on operating systems: three easy pieces. When they introduced fork and exec i was so confused but this video clarifies everything super well. Thanks!
I am late to the party, but you sir are a lifesaver. Thank you so much for creating simple, easy-to-follow tutorials for these complex topics. For some reason, UNIX documentation loves to be cryptic and hard to follow. It feels to me that documentation is there just to be a sort of gatekeeper into these concepts. Your tutorials are the way things have to be taught and explained, at least for a first contact with the topic.
I'm a student and before i watched this video, i watched a lecture of about an hour and didn't understand a thing about forks. 2 mins into this video i already understood more. You're a hero!
You should join it if you haven't already! We're always trying to help people out and looking for others that can help since it's getting a bit more activity than usual. Here's the link: discord.code-vault.net
Thank you so much for this video. I really got a clearer understanding of how forks work but then I have a question. What is the essence of duplicating processes with the fork and displaying the same output multiple times
You can think of processes like apps on your phone. When you open both Instagram and Facebook, in OS, they are two different processes via fork with different memory address space.
Thanks for clarifying this daunting topic, but my question is at what stage or under what conditions would a programmer use fork() function? Or should I say, what is the practical function of fork()?
Usually if you want to launch another program from your own program you would use fork() and then a call to execlp() (or similar function). In some niche cases you could use it to distribute work for an algorithm that is easy to parallelize (although usually threads are what are used in that case).
I wrote a small text based dungeon crawler and I really want to make it so that multiple people can play it. If player A walks into a room that player B is in, player A would get a message like "You are standing in a tiny alcove. Player B is here." And player B would see a message like "Player A has just walked in." Would fork() be the way to go to create a multiplayer experience?
Hmm, I think I would just use threads for this. Creating multiple processes for a simple game sounds a bit much. There's a course on threads here: code-vault.net/course/6q6s9eerd0:1609007479575
@@CodeVault Thanks, I will look at these videos. I have a very basic game working, but I've never tried to make a program that multiple people can run at the same time, so I'm not sure how that works. My thinking is that I'll create a separate account on my Raspberry Pi that I can log into via ssh. I'll have it set up so that when I log into that account, it automatically runs the game. When I first enter the game, I'll have to type in a unique player name and then I'll be placed into the game. Then I can log into that account again via a separate ssh session, type in another unique player name, and the two players will exist in the game at the same time. (And I can log in as many times as I want ... or have friends log in.) But I have to figure out how to make it so that each player can talk to the other players, give items back and forth, explore the dungeon together, kill monsters cooperatively, and so on. repl.it/@blixel/textAdventure
Ohh, that's a bit more complex what you want to do. I think the best way is to use sockets here. You'll need a server that receives updates from clients. So two separate programs. I don't have tutorials on sockets yet. Here's the docs for them: linux.die.net/man/7/socket
@@CodeVault Thanks again for the reply. I've gone down the path of sockets before as well. Using a variety of RU-vid videos as my knowledge base, I've written a basic client/server chat system. I've fiddled around with it and added some of my own ideas like being able to create a username when first getting on, and having the server keep track of usernames so that clients can type "list" to see who is logged in. It was fun and educational, but it seems to me that's not quite how these MUDs work. With MUDs I've played with, you use your regular telnet/ssh client to go from your end to the server, and the MUD daemon on the server does the rest. So I felt like I was going down the wrong path with my client/server socket stuff. When I saw this video on fork(), I thought maybe the game would fork() a new process for each connection, and then players could talk to each other and adventure together. But I don't know. I can't figure out how this multiuser thing works.
Great video. When your mouse went was above the fork() function, it gave you a description of the function. How do you do that in Visual Studio Code? Thank you!
There's this video to set up C/C++ programming for vscode: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-N5GhV8K8DIc.html If you're on Linux, just follow the mingw installation guide but point it to the gcc binaries instead. Should work exactly the same.
Great explanation! I have one question though: when you run a program, a child process is printed first, and then the parent (main) process (3:05). But in my case, the parent process is run first, then the child process. It seems to depend on compilers. Or what?
It depends on many things... Either way, order of execution for processes and threads is undetermined. That's why multi-process and multi-thread programming is difficult.