Last active
December 27, 2019 11:37
-
-
Save aakbar5/cd33daa5cc4093bdead46a069abd71b9 to your computer and use it in GitHub Desktop.
dup2 usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple example of how dup2 can be used | |
const char* msg = "Text written by standard file descriptor\n"; | |
int fd = open("dup2_test.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); | |
write(fd, msg, strlen(msg)); | |
/* Map stdout to our file */ | |
dup2(fd, STDOUT_FILENO); | |
printf("Text written by dup @ stdout file descriptor\n"); | |
close(fd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment