Skip to content

Instantly share code, notes, and snippets.

@enxebre
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save enxebre/9628d6b28165d61bf116 to your computer and use it in GitHub Desktop.

Select an option

Save enxebre/9628d6b28165d61bf116 to your computer and use it in GitHub Desktop.
gdb_redirect_ouput
# From /dev/null to file
gdb -p processpid
(gdb) call creat("/home/me/myprog.stdout",0600)
$1 = 7
(gdb) call dup2(7,1)
$2 = 1
(gdb) call creat("/home/me/myprog.stderr",0600)
$3 = 8
(gdb) call dup2(8,2)
$4 = 2
# From somewhere to /dev/null
(gdb) p dup2(open("/dev/null", 0), 1)
(gdb) p dup2(open("/dev/null", 0), 2)
(gdb) detach
(gdb) quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment