Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometime I need to run an application from terminal for debugging. If I am sure the bug will occur short after launching the application, I can run this application from the Terminal.

However, bugs occur unexpectedly, and then only I need to monitor the buggy application from the Terminal (to see its output).

Can I then pick up an application from terminal, which was not launched using Terminal? If so how?

share|improve this question
I eventually picked up Michał Šrajer's answer because it was the most instructive. But all your answers were just good and appreciated too. Cheers. – Benjamin Sep 2 '11 at 8:13
Previous error messages (to stderr) are written to ~/.xsession-errors if you launched it via GUI. – Lekensteyn Sep 2 '11 at 10:54
up vote 26 down vote accepted

Each process in linux has a special directory /proc/{pid}/fd/. 0 is stdin, 1 is stdout and 2 is stderr. So, assuming you are only interested in diagnostic output you can determine the process pid, and then in the terminal do:

to see stdout:

cat /proc/{pid of process}/fd/1

to see stderr:

cat /proc/{pid of process}/fd/2
share|improve this answer
This answer's the most instructive. Thanks. – Benjamin Sep 2 '11 at 8:10
OK i'm a bit confused, when I run cat /proc/1840/fd/1 it seems to return output from other processes than the one I picked up. (1840 is currently for Skype according to System Monitor) It shows output of other programs too... :| – Benjamin Sep 4 '11 at 14:13

Or you can use strace like this

sudo strace -p $pid_of_the_process
share|improve this answer
Thanks for your answer. – Benjamin Sep 2 '11 at 8:11

You can attach with gdb to a running process.

The syntax is

gdb program pid

Ok, you cannot see source code, if debug information are stripped, which is the default for deployed applications. But you can probably see stdout/stderr and debugger messages, segfaults.

share|improve this answer
Thanks for your answer (again) :) – Benjamin Sep 2 '11 at 8:11
I tried that but it didn't work. For instance System Monitor shows Cairo-Dock ID is 1452, so I run gdb program 1452 (I also tried gdb 1452), but it returns "1452: No such file or directory. " – Benjamin Sep 4 '11 at 14:07
The first one should work. What did it return? – enzotib Sep 4 '11 at 14:13
This is what it returns fully after asking for pid 1840 (Skype): GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-linux-gnu". For bug reporting instructions, please see: <>... 1840: No such file or directory. – Benjamin Sep 4 '11 at 16:50
I said the first one, that with gdb program pid. I think the output you shown is from gdb pid – enzotib Sep 4 '11 at 21:08

You are likely looking for retty. You could also look for "attach tty". Basically it's done using ptrace so you could even roll your own.

share|improve this answer
Thanks for your answer. – Benjamin Sep 2 '11 at 8:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.