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

24. July 2019

Creating Python virtualenv fails with error: Could not find a suitable TLS CA

You can create Python virtualenv using command:

virtualenv -p /usr/bin/python3 py-env3

You may encounter following strange error:

  Collecting setuptools
Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels
...
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /etc/ssl/certs/ca-certificates.crt
...
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 145, in apport_excepthook
    os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o640), 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_virtualenv.1000.crash'

The error message is not very clear. Problem is caused by ca-certificates and it could be fixed by command:

sudo update-ca-certificates