Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. if (fork() == 0)
  2. {
  3.     // child
  4.     int fd = open(file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  5.  
  6.     dup2(fd, 1);   // make stdout go to file
  7.     dup2(fd, 2);   // make stderr go to file - you may choose to not do this
  8.                    // or perhaps send stderr to another file
  9.  
  10.     close(fd);     // fd no longer needed - the dup'ed handles are sufficient
  11.  
  12.     exec(...);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement