Shell – How to observer the desktop GUI interacting with the shell

apiArchitectureguishell

For example, if I change the sound volume by the ubuntu desktop widget, I think it will issue some commands to the shell or run a script.

Is it possible to see what it runs?

Best Answer

Doing something in the GUI does not, in general, invoke shell commands. It happens sometimes, but it's uncommon. Rather, both GUI and command line programs (including shells) call the same underlying programming interfaces.

If you want to understand how a program does something, check its documentation or its source code. You can try to observe it, but it can be difficult to figure out.

On Linux, the strace program lists the system calls made by a program. Find out the process ID of the program (e.g. through the command ps xww), say 1234, and run

strace -p1234 -o widget.strace

Perform the action you want to observe, then kill strace (Ctrl+C in the terminal). Look at the output file and try to figure it out. You'll see a lot of communication with the X server (read and write calls on a particular file description) due to the GUI actions. If the action is performed by the X server, you'll need to analyze that protocol further. You may also observe remote calls via D-Bus; to understand these, run dbus-monitor to get a human-readable trace of the D-Bus traffic. Otherwise look at what else the program is doing.

Sound on Ubuntu normally goes via Pulseaudio. The application uses D-Bus to communicate with the Pulseaudio server. Pulseaudio has a command line interface with programs whose name begins with pa, including pavucontrol to control the volume.

Related Question