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
3
votes
1 answer

Rails Dup: remapping associations

I am cloning an active record model (called Projects) using "dup". It has several associations; a project has many steps, steps have many images and videos, etc. I'm finding that when I clone a project, it's successfully creating clones of the…
scientiffic
  • 9,045
  • 18
  • 76
  • 149
3
votes
2 answers

How to understand the #dup and #clone operate on objects which referencing other objects?

I am not sure about the meaning of "...but not the objects they reference" in both the documantion of ruby and rubinus. In ruby-doc, there is the explanation of #clone and #dup behavior saying: Produces a shallow copy of obj—the instance variables…
steveyang
  • 9,178
  • 8
  • 54
  • 80
3
votes
1 answer

"dup" function, "more" and redirection

I have a problem with this little code for educational purposes. I can not understand how it works. #include #include #define FNAME "info.txt" #define STDIN 0 int main(){ int fd; fd = open(FNAME, O_RDONLY); …
Fabio Carello
  • 1,062
  • 3
  • 12
  • 30
2
votes
1 answer

Strange behaviour when redirecting stdout in C

I'm trying to redirect stdout to a file and then restore it back to original in C, but I'm facing the following strange issue - the following piece of code succesfully writes in stdout in stdout in stdout and in file in the respective file which…
asenovm
  • 6,397
  • 2
  • 41
  • 52
2
votes
1 answer

dup2 a socket to a file

All, winter comes, plz keep warm and keep healthy. During the meditation about the work, I got some question about the function of fd dup2 . I create a socket server, and a client. the server send, the client receive data. But Now I want to dup2 the…
StevenWang
  • 3,625
  • 4
  • 30
  • 40
2
votes
1 answer

Executing the ls | wc linux command in c program using 2 processes communicating trough a pipe

I'm currently having problems with the following exercise: I want to "mimic" the pipe command line ls | wc in linux bash with the following program. What I do is: create a pipe create a reader child and writer child the writer child closes the…
MrRhabdos
  • 33
  • 4
2
votes
1 answer

Piping the stdout of a command to the stdin of another other using shared file and dup2()

I am writing a porgram with takes two arguments - the name of commands. The program should redirect the output of the first to a file 'tmp' than execute it, than redirect the stdin of the second command to 'tmp' and execute the second…
Teodor Dyakov
  • 344
  • 2
  • 13
2
votes
0 answers

Does execlp get blocked until there is data available in FD?

This is a correction for an assignment I got, the assignment is the emulate the command who|grep in a C program. When I tested it, it worked as expected. From my knowledge, when fork is called, the two processes (child and parent) run in the same…
2
votes
1 answer

C stdout to file using dup

I am working on a program that asks the user to input s,f or 0 as user input. S prints a predefined message to the system and f writes that predefined message to a file given by the user as an argument. 0 terminates the program. I need to make the…
HotWheels
  • 444
  • 3
  • 23
2
votes
2 answers

trouble to write in a file with dup2 and printf

I've got a problem with this simple code : int main(int argc, char const *argv[]) { int fichier = open("ecrire.txt", O_APPEND | O_WRONLY | O_CREAT); dup2(fichier, 1); printf("test"); return 0; } I just need to write "test" on my file with…
ztarky
  • 53
  • 1
  • 5
2
votes
1 answer

execlp() failing to retrieve correct input

I've been trying to write a really simple program in which the parent process passes 100 lines to a child process through a pipe. The child should then use the generated lines and execute the command line program more over those lines. However,…
Pedro
  • 23
  • 6
2
votes
1 answer

deep_clone gem not duplicating created_at

I am duplicating a rails object, it is duplicating fine with all details except the created_at value of the object. I am using deep_clone gem for doing deep duplication . Here is the code . I want created_at value of raw_materials and costing_items…
Dev R
  • 1,892
  • 1
  • 25
  • 38
2
votes
1 answer

How can you clone records and their relationships in rails?

I have an App with og_objects, og_actions, and stories I have created a way to create a clone of this app. I am now trying to duplicate the og_objects, og_actions and stories into the clone, but I am getting stuck. I am getting stuck in two places. …
Bob
  • 1,605
  • 2
  • 18
  • 33
2
votes
2 answers

explanation of the dup() system call

Can I get a really dumbed down explanation of the dup() function when it comes for duplicating file descriptors? I want to use pipe, but I have to also make the child to read from pipe(this is the easy part), but write data back to parent. Should I…
Justplayit94
  • 385
  • 2
  • 19
2
votes
1 answer

Possible to copy just the value of an array?

I created a 2-D array and tried to copy its value. I tried assignment, dup, and clone. @grid = Array.new(3) { Array.new(3) } new_grid = @grid.clone Whenever I try to change a value in the new variable, the change is reflected in the original…
frugalcoder
  • 959
  • 2
  • 11
  • 23
1 2
3
11 12