• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

fork(),exec() & dup

Matty2d

Weaksauce
Joined
Mar 30, 2003
Messages
83
I’am in a Systems Unix Programming (C programming) course right now and the book is horrible. I’am really having a hard time grasping fork(), exec() and especially dup. Is there any good online tutorials/slides that could be of some benefit to me, I’ve done some “googling” but have found nothing really good.

Thanks
[]v[]
 
Originally posted by Matty2d
I’am in a Systems Unix Programming (C programming) course right now and the book is horrible. I’am really having a hard time grasping fork(), exec() and especially dup. Is there any good online tutorials/slides that could be of some benefit to me, I’ve done some “googling” but have found nothing really good.

Thanks
[]v[]

What's the book?
 
I had a similiar problem with my book which is Modern Operating Systems by Andrew S. Tanenbaum.

The book is a really easy read, because it's written in a very down to earth style, but when it comes to system calls, it absolutely is horrible.

I ended up just reading the man pages and reading example code online to learn about dup, pipes, fork, execlp.
 
Yeah... man-pages are teh way to go; if you don't have a unix system available to you, you're pretty much fucked when it comes to figuring out unix OS concepts.


fork() creates a new process that's an (almost) exact copy of the current one; the difference is that the new process gets a 0 while the original one gets the pid of the new (child) process. The two processes then 'simultaniously' go to the next instruction after the fork().

exec(), OTOH, essentially stops your process and starts up a new one in its place.

dup() is the simplest one of the bunch, but until you figure out how fork() works, its going to seem useless. File descriptors, in unix, are simply integers; dup just gives you another file descriptor to describe the same open file.
 
The book is actually a Courseware book (written' by the my professor, Computer Science Professor's are not the best writters), n e wayz, that helped me out a little, on that dup(), i seen alot of example online used with Streams and Sockets, what does it actually do in those cases?



[]v[]
 
Well, when we used dup in my class, we duped filters into thinking they were reading from stdin, but they were really reading from the inside of a pipe and dup'ed it from thinking they were writing to stdout, but were instead writing to another pipe.

Like you could write 2 filters, one filter that converts from decimal to hexidecimal, and another filter that converts from hexidecimal to binary, and then set up a pipe between your main program and dec-to-hex and a pipe from dec-to-hex and hex-to-bin, and one more pipe from hex-to-bin to your main program. Then dup dec-to-hex to think that it's reading from stdin, but instead reading from the pipe, and instead of stdout, it'll write to stdout.

I'm sure it's a similiar idea with sockets and streams, but I could be wrong. =/
 
Back
Top