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

True file descriptor clone

Why is there no true file descriptor clone mechanism when possible, like it is for disk files. POSIX: After a successful return from one of these system calls, the old and new file descriptors may be used interchangeably. They refer to…
user877329
  • 6,717
  • 8
  • 46
  • 88
0
votes
1 answer

fork, pipe exec and dub2

This code is supposed to print "Output from 'ls -l':" and append the result of 'ls -l', but it doesn't... Does anyone has a clue whats wrong with this? #include #include #include #include void…
Robin des Bois
  • 355
  • 2
  • 6
  • 20
0
votes
1 answer

sed command using pipes causes infinite loop

So I am trying to use pipes to cat a file and to sed into a file called newfile.txt Currently the cat command works, using execvp, however it's outputing onto the command display. And then the program goes into an infinite loop when it goes to the…
0
votes
1 answer

x86 array declaration with multiple 'DUP' - what does it do?

I'm studying x86 assembly, and I've come across this declaration: array1 DB 5 DUP(2 DUP('*')) What does this declaration do? Allocates space for an array called array1, with size DB * 5 * 2 = 10, and 10 * elements. Allocates space for an array…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
0
votes
1 answer

Redirect to execlp()

I have a problem with execlp. When I do not know how to redirect command from arrays of pointers to execlp correctly. For example i want to use ls -l | sort -n my program takes only "ls" and "sort" int pfds[2]; pipe(pfds); …
0
votes
1 answer

Read file to standard in for parser

I am trying to implement a shell program in a linux environment. The part I am having trouble with is reading a setup_file inside of a shell before running the shell, to do things like set environment variables. Currently the shell has a…
Kt Mack
  • 381
  • 4
  • 17
0
votes
0 answers

I am having trouble redirecting my output back from file to standard out C

I have looked all over the internet and die.net and can't see to make my code work. My problem is that I am able to redirect the output to a file, but have trouble bringing it back to standard out, I have tried using dup, dup2 and close, but maybe I…
0
votes
1 answer

How does dup work on jagged arrays?

I would expect it to duplicate only nested arrays slices instead of the whole deep copy of array, but suddenly I've got a doubt.
akalenuk
  • 3,815
  • 4
  • 34
  • 56
0
votes
1 answer

C++ - How to fully wrap a subprocess

My goal is to: Pipe stdin to stdin of child process. Pipe stdout of child process to stdout. Pipe stderr of chile process to stderr. I have looked at…
corbin
  • 1,446
  • 2
  • 27
  • 40
0
votes
1 answer

understanding system call dup()?

Wanted to know what happens to the global file table and inode table when I do dup() I know it returns an int, and it opens a new file descriptor in the file descriptor table
sdafad
  • 359
  • 1
  • 2
  • 7
0
votes
2 answers

opening descriptor and closing , why does it matter?

i have the following code it prints to the screen: haha to the file : haha hello Father finished if i remove line 6 and 7 , I get different results why? int main() { // creates a new file having full read/write permissions int fd =…
0
votes
1 answer

dup return error (c programming in linux)

I'm trying to create a simple program which simulates the "ls -l | tail -n 2" call in terminal. I'm using "fork" and "execvp" for that purpose. Well, here is the code: int main(int argc, char *argv[]) { int pipefd[2]; pid_t child1; pid_t…
Aladin
  • 492
  • 1
  • 8
  • 21
0
votes
1 answer

Cant find element in clone document

I am using Nokogiri (1.5.9 - java) in JRuby ( 1.6.7.2 ) to copy an XML template and edit it. I'm having problems finding elements in the cloned document. lblock = doc.xpath(".//lblock[@blockName='WINDOW_LIST']").first lblock.children = new_children…
sFrenkie
  • 1
  • 2
0
votes
1 answer

IO redirection and buffer issues, fflush and c

for my class we are to implement a shell with output redirection. I have the output redirection working, except my first command is always corrupted see: $ echo this doesn't work H<@?4echo No such file or directory $ echo this does work this does…
Harrison
  • 430
  • 2
  • 6
  • 13
0
votes
3 answers

Saving/duplicating a file pointer/descriptor

I have a requirement where in there is a global FILE pointer/descriptor. One of the functions will read from this pointer/descriptor. The internal pointer associated with the FILE pointer/descriptor advances. After this function returns, I want to…
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
1 2 3
11
12