Questions tagged [dup]

dup() is a c system call that duplicates a file descriptor

Usage: int dup(int oldfd); (#include <unistd.h>)

The C system call dup duplicates a file descriptor. It returns a second file descriptor that points to the same file table entry as precious file descriptor does, so that we can treat the two file descriptors as identical.

The dup system call uses the lowest-numbered unused file descriptor as its new file descriptor. Compare which has two arguments, and that you specify the new destination file descriptor number in the second argument.

See http://man7.org/linux/man-pages/man2/dup.2.html for more details.

176 questions
0
votes
1 answer

A bug in rails? About model inherited

My env: ruby-1.9.2-preview3; rails-3.0.0.beta3 class PostFather < ActiveRecord::Base def self.inherited(subclass) end end class Post < PostFather end In the console: > Post.new # => TypeError: can't dup NilClass > Post.all # => TypeError:…
Croplio
  • 3,433
  • 6
  • 31
  • 37
0
votes
1 answer

make STDOUT_FILENO a new file handler

I'm confused about executing a file with "> /home/hel/myfile".Is this toally equivalent to dup2(fd, STDOUT_FILENO) if fd is the file hander of "/home/hel/myfile"? As for kernel, do they work in the same way? #include #include…
hel
  • 581
  • 10
  • 26
0
votes
1 answer

Removing duplicate-like function which uses static to denote the class name in PHP

Is there a way to get rid of the getCopy() method in the derived class HelloAndGoodbye, given that it looks the same as the getCopy() in the base class Hello? And what is more, what is there an efficient way to achieve this? (the only difference…
John Sonderson
  • 3,238
  • 6
  • 31
  • 45
0
votes
0 answers

How to achieve redirection in a c shell?

How do i use dup (or dup2) to achieve redirection, in other words to execute commands like sort < in.txt > out.txt. *System calls that create a new shell like (bin/sh/) are not allowed.
0
votes
0 answers

C joining two character devices

I've two devices one is a pts (/dev/pts/N) another is a socket(/path/to/socket). I want infinitely read the pts and write that to socket, and infinitely read socket and write to pts. What I am doing right now is to open both and create a read loop…
Neel Basu
  • 12,638
  • 12
  • 82
  • 146
0
votes
1 answer

redirect stdin from file descriptor in linux c

I can't understand what's wrong with the following code. I perform exactly the same actions twice. It works for the first time, and fails for the second. open FD duplicate to stdin. close stdin close the original fd At the second time I get an…
Tzafrir
  • 639
  • 8
  • 15
0
votes
0 answers

Multiple redirects with dup and dup2

I implement some parts of shell. One of them is a pipe. During the parsing I exec commands redirecting their input/output with dup2. Specifically I do the following (I don't write here error checking for simplicity, but I check for errors in my…
perlik
  • 93
  • 6
0
votes
1 answer

I want to know the meaning of this phrase in assembly language

i am supposed to code a loop that moves zeros to each byte of DATE_TBL: DATE_TBL DB 25 DUP(?) But i am not sure what the code DB 25 DUP (?) does I know DUP means duplicate and DB means define byte
0
votes
1 answer

How to connect the old descriptor with the new descriptor?

Consider i have opened the file as hell.txt with the open() function. fd=open("hell.txt",O_RDONLY); then, consider it will return the descriptor as 4. and hi.txt already occupy the descriptor 3, so i want to connect the hell.txt file with 3…
Bhuvanesh
  • 1,269
  • 1
  • 15
  • 25
0
votes
2 answers

closing a pipe and duplicating a pipe

I'm trying to understand how pipes work and it is rather confusing when I was reading this code in my textbook. In the line dup(fd2[0]); close(fd2[0]); why are we duplicating fd2[0],then close it right after we duplicated it? #include…
Learning
  • 13
  • 1
0
votes
1 answer

Why does dup() and popen() prevent my process from exiting when called from another process?

I've a program which popen() to another and also dup() stdout When called from another process (like the PHP example) or via SSH, the process does not exit. process_test.c: #include #include int main() { int out; out =…
mark
  • 6,308
  • 8
  • 46
  • 57
0
votes
1 answer

c dup undefined error

I'm trying to create two child processes: One child reads its input from a file, which is passed in as an argument, and writes output to the pipe. The other child reads its output from the pipe and writes its output to a file, also passed in as an…
braab
  • 87
  • 2
  • 11
0
votes
1 answer

Ruby object ID, dup, and mutability

I've come across the following concern in Ruby a = [1, 2, 3] b = a b.delete_at(1) b => [1,3] a => [1,3] b.object_id => 70178446287080 a.object_id => 70178446287080 So I kind of have an understanding of this. a holds a reference to an array at the…
user3278117
  • 95
  • 1
  • 8
0
votes
1 answer

Working of dup3

While reading dup3 system call, I got that it will change only O_CLOEXEC flag of duplicated file desriptor. But when I have written below program for all the 3 outputs it printed the flag is either present or not and it is based on whether O_CLOEXEC…
Sanjay Bhosale
  • 685
  • 2
  • 8
  • 18
0
votes
0 answers

Piping with an array of commands

I have a function that takes an array of strings and the size of the array. I have a loop that tokenizes the string into command and arguements and then forks and executes the commands one by one. For each command I need to pipe the output to the…