Top "Dup2" questions

dup2() is a c system call that duplicates a file descriptor.

Pipes, dup2 and exec()

I have to write a shell that can run pipes. For example commands like ls -l | wc -l". I have …

c linux shell exec dup2
Using dup2 for piping

How do I use dup2 to perform the following command? ls -al | grep alpha | more

c linux dup2
Can someone explain what dup() in C does?

I know that dup, dup2, dup3 "create a copy of the file descriptor oldfd"(from man pages). However I can't …

c pipe dup2 dup
Having trouble with fork(), pipe(), dup2() and exec() in C

Here's my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <…

c exec fork pipe dup2
In C, how do I redirect STDOUT_FILENO to /dev/null using dup2 and then redirect back to its original value later?

I have an assignment I'm working on and I'm having difficulty finishing it. The idea is to write a program …

c fork stdout dup2 dup
What does dup2() do in C

I looked it up in the man page but I still don't get it... let's say you have dup2(f1,0). …

c pipe file-descriptor dup2
Can popen() make bidirectional pipes like pipe() + fork()?

I'm implementing piping on a simulated file system in C++ (with mostly C). It needs to run commands in the …

c fork pipe popen dup2
Trouble with dup2, stdout, and stderr

When this program is run, the "stderr" line is displayed before the "stdout" line. Why? I thought dup2 would make …

c fork stdout stdin dup2
Using Dup2 to Redirect Input and Output

I have been writing a Unix shell in C, and I am attempting to implement input and output redirection. I …

c dup2
How do you use dup2 and fork together?

I'm taking an operating systems course and I'm having a hard time how input is redirected with dup2 when you …

unix exec fork dup2