I have migrated to Ubuntu 16.04 just 2 days ago from Windows. I like the way we can customise the Unity Desktop. I am just playing around with the look and feel of the Desktop environment. Just like in Windows, I wanted the launcher to be at the bottom of the screen. On Googling, I found a command which goes like:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
Also, there are the unity-tweak-tool and dconf editor to get the job done. But these are the GUI approach of getting things done.
My questions are:
- Do these GUI-based applications also execute the same command in the background?
- How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
- Do these applications open up a terminal in the background and execute these commands?
The answer here tells how to get the process's standard file descriptor. But, I did't get anything in the output.
Moreover, the strace -p pid -o output.txt
command throws a huge amount of text into the file.
So, in short, is doing things using GUI applications same as doing stuff from the commandline?
Best Answer
Yes and no. They write to the
dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use thegi.repository.Gio
module (I know because I use it a lot) or they can instead usegsettings
as an external command by callingsubprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely agio.h
library, or it could even use theexec()
family of functions to do the same asPopen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the
Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use
dconf watch /
to see what settings are being changed, but not how it's done.Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
No, there's no terminal attached. Many programs know where the
dconf
database for the user is located and write there. There's also an inter-process communication bus known asdbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactivelythe shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.