The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
system calls sangramdas BSD 1 05-08-2008 05:48 PM
System calls joshighanshyam High Level Programming 1 03-19-2008 04:57 AM
System calls ? TECHRAMESH SUN Solaris 1 05-15-2006 10:05 PM
System calls? PlunderBunny UNIX for Dummies Questions & Answers 2 03-26-2006 06:12 PM
System calls for cp and mv gaurava99 UNIX for Dummies Questions & Answers 2 04-25-2005 07:04 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2001
Registered User
 

Join Date: Oct 2001
Posts: 7
Talking System Calls

What does the system call "dup" do?

What is the difference between dup and dup2

I have a fair idea of what it does but I am confused when its coming down to the exact details...

Please help me!
Forum Sponsor
  #2 (permalink)  
Old 10-06-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
dup is a system call vs. dup2 which is a
C library call. As I gather you alreay know,
dup creates a new file descriptor that duplicates
the file descriptor given as the argument:
int dup(int fildes);
...the point here being that the returned file descriptor that the system call returns to you
is the next lowest number available. For instance,
you program has stdin (fd=0) stdout (fd=1) and
stderr (fd=2) and you use: newfd = dup(2);
now newfd = 4 but has all the attributes of
fd 2 (stderr).

The C library call dup2 has 2 arguments...
int dup2(int fildes, int fildes2);
...by using: dup2(1, 2);
the stderr fd 2 will first be closed then opened
(re-created) with all the attributes of file
descriptor 1 (stdout). Basically, it gives you
control over what your new fd number will be.

This isn't a very useful example but
I hope this answers your question.
  #3 (permalink)  
Old 10-06-2001
Registered User
 

Join Date: Oct 2001
Posts: 7
Smile Thanks rwb1959

Thanks very much.
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0