Tag: linux

How to enter ASCII control characters with your keyboard

close photo of a macbook pro keyboard

How to enter ASCII control characters?

Entering ASCII control characters depends on the specific keyboard layout and operating system you are using. Here’s a general guide for Linux, Windows, and macOS:

Linux

In most Linux terminals, you can enter ASCII control characters using the keys Ctrl + Shift + u in combination with a letter or symbol. For example:

  • Ctrl + Shift + u and then 0 + 1: ASCII code 0x01 (Start of Heading)
  • Ctrl + Shift + u and then 0 + 2: ASCII code 0x02 (Start of Text)
  • Ctrl + Shift + u and then 0 + 3: ASCII code 0x03 (End of Text)
  • And so on…

Windows

In the Windows operating system, you can use the following steps:

  1. For characters with ASCII values 0 to 31, you can typically enter them using the Alt key and the numeric keypad. For example, to enter ASCII 0x01, press Alt + 0 + 0 + 1.
  2. For some characters, you can use the Windows Character Map utility. Press the Win key + R to open the Run dialog, type charmap, and press Enter. Select the desired character and copy/paste it.

macOS

On macOS, you can use the following steps:

  1. Character Viewer: Press Control + Command + Space to open the Character Viewer. Search for the desired control character and insert it into your document.

Note that you may have to go to the dots menu at top left and select Customize to add the Unicode category. The Unicode category is under Code Tables.

Note: The availability of these methods may vary depending on your keyboard layout and the specific software you are using. If you’re using a specific text editor or terminal, it might have its own way of entering control characters.

What are ASCII control characters?

ASCII control characters are special characters in the ASCII (American Standard Code for Information Interchange) character encoding scheme that are used to control peripheral devices such as printers and teletypewriters. They are non-printable characters and typically have specific functions rather than representing printable symbols like letters or numbers.

Here is a list of some commonly used ASCII control characters along with their decimal and hexadecimal values:

Control CharacterASCII DezimalASCII HEXDescription
NUL000null character
SOH101start of header
STX202start of text
ETX303end of text
EOT404end of transmission
ENQ505enquiry
ACK606acknowledge
BEL707bell (ring)
BS808backspace
HT909horizontal tab
LF100Aline feed
VT110Bvertical tab
FF120Cform feed
CR130Dcarriage return
SO140Eshift out
SI150Fshift in
DLE1610data link escape
DC11711device control 1
DC21812device control 2
DC31913device control 3
DC42014device control 4
NAK2115negative acknowledge
SYN2216synchronize
ETB2317end transmission block
CAN2418cancel
EM2519end of medium
SUB261Asubstitute
ESC271Bescape
FS281Cfile separator
GS291Dgroup separator
RS301Erecord separator
US311Funit separator
   
DEL1277Fdelete (rubout)

Foto von Jess Bailey auf Unsplash

 

CUDART Error in Singularity Container Workaround

Singularity is a Linux container system similar (and compatible to) Docker. It’s advantage over Docker is that is was designed to allow users without superuser privileges to run containers within their environment. I recently encountered the following error when running a Nvidia CUDA application within a Singularity container using “singularity run -nv <container>:

CUDART: cudaGetDeviceCount(&deviceCount); = 999 (unknown error)

Workaround: After running /usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery outside of the container, the CUDA application within the container ran without any problem.

Fix/Solution: TODO

 

Finding the NUMA Node of a Nvidia CUDA GPU in Linux

For some applications it might be useful to pin their CPU processes to the NUMA node which is connected to the GPU. To find out which GPU is located at which NUMA node one can use the following script:

for i in $(nvidia-smi -x -q | grep "gpu id" | awk -F "\"" '{print $2}' | awk -F ":" '{print "0000:"  $2 ":"  $3}' | tr '[:upper:]' '[:lower:]'); do echo $i; cat "/sys/bus/pci/devices/$i/numa_node"; done

Pinning the CPU process to the right NUMA node can speed up your application significantly on all Nvidia GPUs like the double precision HPC GPUs Tesla V100, A100 and A10, the professional Quadro RTX GPUs as well as all CUDA capable GeForce GPUs.

BASH: Nach jedem xten Zeichen ein Zeichen in einen String einfügen

Mit sed "s/.\{x\}/& /g" kann man in eine Zeichenkette alle x Zeichen ein Leerzeichen automatisiert einfügen. Aber auch andere Zeichen sind möglich. So kann man bspw. alle zwei Zeichen einen Doppelpunkt in einen String einfügen:

#~> echo "AA11CC22EE" | sed "s/.\{2\}/&:/g"
AA:11:CC:22:EE:

Sollte das letzte Zeichen stören, kann man dies wie folgt entfernen:
#~> a = $(echo "AA11CC22EE" | sed "s/.\{2\}/&:/g")
#~> echo ${a%?}
AA:11:CC:22:EE

VI oder VIM beenden

Um den bei vielen Linux und Unix Installationen und Tools (wie bspw. git) standardmäßig genutzten VI Editor zu beenden muss man mit der “ESC”-Taste in den Kommandomodus wechseln (am besten mehrfach drücken um ggf. schon eingegeben Kommandos abzubrechen). Und dort dann

> :q

eingeben und Enter drücken.
Dies beendet VIM wenn vorher nichts geändert wurde.

Wurde etwas am Text der geöffneten Datei geändert und man will dies speichern so nutzt man den Befehl:

> :wq

Will man die Änderungen verwerfen und VI verlassen, so hilft:

> :q!

Ein sehr hilfreiches und detailliertes Cheat Sheet zum Nachschlagen selten benutzter Befehle findet sich unter: https://devhints.io/vim

Auszug eines Cheat Sheets für VI/VIM

NVIDIA CUDA on Ubuntu: unsupported GNU version! gcc versions later than 5 are not supported!

After installing CUDA on Ubuntu, compiling CUDA applications with nvcc results in an error similar to this:

In file included from /usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/cuda_runtime.h:78:0,
from <command-line>:0:
/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/host_config.h:119:2: error: #error — unsupported GNU version! gcc versions later than 5 are not supported!
#error — unsupported GNU version! gcc versions later than 5 are not supported!
^~~~~}}}

Ubuntu comes with a more up-to-date GCC then CUDA can handle. To solve this issue we install GCC 4.9:

sudo apt install gcc-4.9 g++-4.9

Now GCC 4.9 and the up-to-date GCC are installed on the system. To be able to use the up-to-date GCC without CUDA, one can setup and use the “update-alternatives” system for GCC. In this case we replace the default GCC 6 compiler:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

Now we can list the available compilers with

update-alternatives --list gcc

and set the GCC 4.9 as default with

update-alternatives --set gcc /usr/bin/gcc-4.9