fd, dup()/dup2() system call tutorial
ฝัง
- เผยแพร่เมื่อ 12 ธ.ค. 2014
- In this video, we illusrate the basics of dup() and dup2() and how you can use these system calls to modify the file descriptors of your system. Modifying these file descriptors will allow us to change the direction of input and output of our program (e.g: instead of having our program read stdin from the terminal, we can have our program read stdin from our file, instead).
When you don't get it from the man page for 30 minutes and get it from a 4-minute video made in 2014...
It just means u didnt get it at all :)
@@unknown_try1 It just means that the man page is meant or other people with decade+ experience and not your average person trying to learn
You're describing this better than the prof. Thank you!
You saved me from failing system programming. God bless you both
From your videos I learned faster, I can't believe myself, you guys make it look easy !
Was having a hard time understanding dup/dup2 until I saw this video. Thanks guys!
Very well performed guys. Well done.
Best video of dupp in youtube ! congrats guys !
From 42Paris, Thank you for this video !! I obviously subscribe and hope you will do more videos (ok, 6 years after this one :( ) . I will talk about your videos in 42! It is so easier to understand by drawings than by code . MERCI
I got an assignment involving pipes - and I had no idea what a file descriptor or the dup() system call was. I would've been screwed without this tutorial. Thank you so much!
such more i learn, more my loving for programming increases
Awesome video guys!! Made a very strange concept very easy to grasp!!
An excellent explanation, thank you very much.
Amazing work. Perfectly clean and succinct
Thank you! It is a lot more information that I could find in other videos!❤
Thank you so much im gonna go through your whole channel rn maybe ill pass the course
thank you so much! this was really helpful.
This is awesome. Thanks a lot!
tnx this video really helped with my assignment!!
U guys helped me so much! Thanks!!!!
Really nice and clear video, thank you guys :)
This was like a dream. Thanks.
Very nice helpful video, thanks a lot guys.
Super useful, thank you for the upload :)
Very succinct. Well done.
awsome work guys.... keep up with good work
awesome video thanks a lot
Awesome bro thank you both
Thanks guys a lot!
The best! Thank youu
thanks a lot guys!
thank you so much!!:)
9 months later I'm back at this video again. Still begging you two to become profs
Great job, Gentz! :c)
very very thnx.
keep up the good work
Thank you!
very helpful. Thanks
Your videos are quite good. Why don't you make more? Do you still code?
well choreographed
Awesome vid
its awesome
Thanks
This was a lot of good information. But I'd like it to better explain the part where we open a file into the fd[0] slot. and how that's done.
Like this:
close(0);
dup(newfd);
It works because dup() will always use the lowest numbered unused descriptor for the new descriptor and since we closed stdin (0) it'll use that.
The above is almost equivalent to:
dup2(newfd, 0);
So dub2() also calls close() ?
@@notker88 Yes, however it isn't recommended to do the step yourself
It is preferable for you to use dup2() alone rather than close() -> dup2() (with dup() you can't really control what file descriptor ot will be copied to) because of race conditions
thanks
damnnn so cool
U didn't explain how u replace stdin with your own file, u just wrote "ourfile".
Does anybody know how did he actually fill slot 0 with ourfile
u dont have to say the Programm to read from Slot 0. this is a Default Setting. it reads whatever it finds in Slot 0.
I think something like this
int file_descriptor_new = open("OurFile", .., .. ) // give option flags and mode of your choice
close(0); // you are closing stdin
dup(file_descriptor_new);
here dup will make file_descriptor_new to point to "OurFile"
P.S. I am not sure if this is 100% right. Correct me if I am wrong. Thanks
goated
Why did you guy's stop uploading videos?
How did you learn this?
well done , but next tutorial take your time and talk please more slowly , because you understand it already , but we have to follow you . and the last words in every sentence you say are low in voice like a song when it ends , be more clear. please. but thank you its a very helpfull tutorial. but take more time , we have time thats what learning is about , taking time ..... thanks
Unix is kinda hacky but better than what was available at the time which was nothing
I miss Brendon and Paul 🥺
It's kinda misleading to describe files like that, because that's not how they appear in memory.
When you say
FILE *f = fopen(...);
you are initializing a struct _IO_FILE in memory, and saving a pointer to the resulting block. The file descriptor described in the video is the member (struct _IO_FILE *)->_fileno.
pastebin.com/raw.php?i=78tpKe2G
Braden Best this was very helpful especially with the commented code at pastebin. I don't know why this comment didn't receive any attention.
牛逼
Everytime mfs search up my name they get this shit and it’s his last upload 6 years ago. HE LEFT ME WITH A CURSE😂
it would've probably been a good idea to mention the assert function to test if the closes and dups actually worked. it can at least be used while youre coding the program and removed at a later stage just for ease of debugging.
because he's asian doesn't mean he cant narrate. Give my man some confidence cmon
Pretty sure they were previous students at my University, as my professor links to these videos and says so. And the projects are partner projects, so these two probably both had to participate for EC points.
if you two choose to become profs youll have 5/5 on ratemyprofs ;)