22. April 2021

How to run Linux GUI application on Windows WSL2 with MobaXterm and Windows Terminal

MobaXterm is a great software that allows running applications from Linux on Windows in a nice integrated way without the need of installing extra XServer.

MobaXterm has also support for WSL2 which makes it easy to launch Linux GUI applications from Linux on Windows.

After installation of Linux distribution like Ubuntu or openSUSE on WSL2, you will find new sessions with the prefix WSL in MobaXterm. Simply click the session label and a new terminal will be automatically configured to talk to the local XServer.

Now you can start any GUI command, e.g. xeyes.

The same XServer from MobaXterm can be used also from other terminals and shells like Windows Terminal. It’s sufficient to export environment variable DISPLAY in the Linux WSL2 session:

export DISPLAY=127.0.0.1:0.0
xeyes

Note: xeyes are part of x11-apps, you can install them by command

sudo apt install x11-apps

26. August 2020

How to run multiple Bash commands in parallel

If you’d like to run multiple commands in shell which is executed one by one, you can simply type:

command1; command2; command3.... commandn

What if you need to run all these jobs in parallel. When you have just single command you can add & and the command will be executed in the background. So the temptation for a solution might be:

command1 &; command2 &;... commandn &

Well, it does not work. The correct solution for oneliners is simple. Just replace ; by &

command1 & command2 & command3 & ... commandn

The same solutions works also for other shells like zsh.

21. August 2020

Common mistake why GDB debugger does not work in Visual Studio Code

Visual Studio Code has great C/C++ support and it’s possible to debug a project with it.

Visual Studio Code can use gdb as a debugger.

If you have your project with a binary and you press F5 to launch the debugger, then Visual Studio will prompt you to configure GDB launcher in launch.json.

Here is sample launch.json for binary my_application on Linux:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/my_application",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }  
    ]
}

Just define a path to your binary, save the file and press F5.

Still, it might happen that debugger does not stop at your break point. Why?

There is one very common mistake. People often forget to add -g for gcc parameter when building the project.

GCC without parameter -g will build a release version of the project without debug information. To fix the problem just add -g to your Makefile, clean, and rebuild the project.

10. August 2020

How to increase font size in Konsole

Konsole is a great terminal emulator that you can find in many Linux distributions. The problem with some Linux distributions is that font is too small.

To change the font open menu Settings and select Edit Current Profile…

Select Preview tab and change Text size value in the middle of the screen. Click Ok to confirm the new font..

Another option to change the font size is to press CTRL and Scroll Up/Down with mouse wheel.

The same result could be also achieved by keys CTRL and +/- keys.

16. July 2020

systemctl Failed to list units: Access denied

During the upgrade of Debian or Ubuntu server you may encounter strange failing of scripts which are restarting services.

For some reason it’s not possible to call systemcl and any operation fails with Access denied even for root.

Here is example:

systemctl list-units
Failed to list units: Access denied

The fix to this problem it is sufficient to send TERM signal to process with PID #1:

kill -TERM 1