Where does the output from an application started from the window manager go

logsstdoutxorg

If you start an application from a terminal you can see the output to stdout and stderr, but if an application is started from the window manager, where does the output to these files typically go? To /dev/null?

Best Answer

The output of an application started from the window manager goes to the same place as the output from the window manager itself. (Unless the application redirects it, but typical GUI applications don't.)

You can find out where the WM's output goes by looking at what it has open on file descriptor 1 (standard output) and file descriptor 2 (standard error); typically both will go to the same file. Find out the process ID of your window manager (try e.g. pgrep metacity or pidof metacity if Metacity is your window manager — if you don't know the process name for your window manager, look at the root of one of the process trees reported by ps f or pstree). Supposing the process ID of your window manager is 1234, run

lsof -p1234

and look for the lines corresponding to file descriptors 1 and 2, or

or

ls -l /proc/1234/fd

You can automate the filtering of the relevant file descriptors:

lsof -p1234 | awk '$4 ~ /^[12][^0-9]/'
ls -l /proc/1234/fd/[12]

(Note: all the commands above are for Linux. pgrep is common among other unices, and lsof can be installed pretty much anywhere; ps options and /proc contents are different across different unices.)

In the common situation where you're running commands from a shell running in a terminal emulator (xterm, konsole, gnome-terminal, etc., but not when used across screen or tmux), then you can easily check where the terminal emulator's output is going, as the terminal emulator is the parent process of your shell. This doesn't work if the terminal emulator is running with additional privileges, which happens on some systems to allow the terminal emulator to write to the logged-in user list (utmp).

lsof -p$PPID
ls -l /proc/$PPID/fd

Many distributions direct the output of the X session to ~/.xsession-errors.

Related Question