Both make a new file descriptor corresponding to an existing open file description. Most properties between the old and new fd (like position) are shared; the only property I can think of that’s not shared is the close-on-exec flag. The difference between dup
and dup2
is that dup
assigns the lowest available file descriptor number, while dup2
lets you choose the file descriptor number that will be assigned and atomically closes and replaces it if it’s already taken.
Related Posts:
- What does it mean to write to stdout in C?
- wait(null) and wait(&status) C language and Status
- How to get the current directory in a C program?
- Reasoning behind C sockets sockaddr and sockaddr_storage
- How to pretty print XML from the command line?
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What are file descriptors, explained in simple terms?
- How to kill a process running on particular port in Linux?
- Display exact matches only with grep
- What are .a and .so files?
- Connect: Socket operation on non-socket
- Connect: Socket operation on non-socket
- How to split a delimited string into an array in awk?
- What is the difference between read and pread in unix?
- Display exact matches only with grep
- What does ^M character mean in Vim?
- What is a bus error? Is it different from a segmentation fault?
- What does WEXITSTATUS(status) return?
- What do ‘real’, ‘user’ and ‘sys’ mean in the output of time(1)?
- mkdir’s “-p” option
- Shell script “for” loop syntax
- What is a bus error? Is it different from a segmentation fault?
- What can cause a “Resource temporarily unavailable” on sock send() command
- When could or should I use chmod g+s on a file or directory?
- How to Sum a column in AWK?
- Equivalent of *Nix ‘which’ command in PowerShell?
- What is the difference between SIGSTOP and SIGTSTP?
- How to colorize diff on the command line
- How to colorize diff on the command line
- How to read a file into a variable in shell?
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- Is there any simple way to benchmark Python script?
- gpg decryption fails with no secret key error
- What is the difference between tar and zip?
- Display current path in terminal only
- Which of sprintf/snprintf is more secure?
- C fopen vs open
- What is `S_ISREG()`, and what does it do?
- Reaching EOF with fgets
- What generates the “text file busy” message in Unix?
- How can I send an email through the UNIX mailx command?
- Rename multiple files based on pattern in Unix
- What is the difference between a symbolic link and a hard link?
- SCP Permission denied (publickey). on EC2 only when using -r flag on directories
- binary operator expected error when checking if a file with full pathname exists
- What is special about /dev/tty?
- How do I do ‘mount –bind’ in /etc/fstab?
- How to read backward from the end of file in less or more?
- Getting the last match in a file using grep
- How do I pause my shell script for a second before continuing?
- What is the effect of extern “C” in C++?
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- In the shell, what does ” 2>&1 ” mean?
- Floating point exception (core dumped)
- Correct format specifier for double in printf
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- What is the difference between char s[] and char *s?
- How do I grep recursively?
- Error “initializer element is not constant” when trying to initialize variable with const
- warning: implicit declaration of function
- C dynamically growing array
- Argument list too long error for rm, cp, mv commands
- How to printf “unsigned long” in C?
- Difference between using “chmod a+x” and “chmod 755”
- Why do I get an assertion failure?
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- expression must have integral type
- OSError – Errno 13 Permission denied
- Why is %c used in C?
- c array – warning: format not a string literal
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- How to convert const char* to char* in C?
- Scanning Multiple inputs from one line using scanf
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- error: too few arguments to function `printDay’ (C language)
- Implementing a HashMap in C
- What does “&” at the end of a linux command mean?
- Optional arguments in C function
- Where is the
header file on Linux? Why can’t I find ? - How to display hexadecimal numbers in C?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- Difference between char *argv[] and char **argv for the second argument to main()
- How do you format an unsigned long long int using printf?
- error : storage class specified for parameter
- Dereference void pointer
- Use of flag in c?
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory
- Level vs Edge Trigger Network Event Mechanisms
- How to convert integers to characters in C?
- variably modified array at file scope in C
- How to use random() in C [duplicate]