Was sind diese Threads namens disk $0, disk$1 usw.?
Ich verwende Ubuntu 20.04 LTS. Die Kernel-Version ist 5.4.0-42.
Hier ein Beispielprogramm:
// mre.c
// Compile with: cc -o mre mre.c -lSDL2
#include <stdio.h>
#include <SDL2/SDL.h>
int main(void)
{
SDL_Init(SDL_INIT_VIDEO); // Doesn't work without SDL_INIT_VIDEO
getchar();
}
Wenn ich mir das laufende Programm ./mremit htopaktivierten Thread-Namen ansehe, sehe ich, dass es diese vier Threads hat:
mre:disk$3mre:disk$2mre:disk$1mre:disk$0
Und hier sind einige Threads /usr/libexec/ibus-x11mit ähnlichen Namen:
ibus-x1:disk$3ibus-x1:disk$2ibus-x1:disk$1ibus-x1:disk$0
Viele Programme haben sie nicht (vielleicht verwenden sie keine bestimmte grafische Oberfläche?)
Solche Threads kommen immer zu viert (mein Computer hat vier Kerne) und werden in absteigender Reihenfolge aufgelistet. /usr/lib/xorg/Xorghat acht dieser Threads, zwei von jeder Nummer 0-3. Wofür sind sie?
Antworten
Diese Threads werden für den Mesa-Disk-Cache verwendet :
util_queue_init(&cache->cache_queue, "disk$", 32, 4,
UTIL_QUEUE_INIT_RESIZE_IF_FULL |
UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY |
UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY);
https://sources.debian.org/src/mesa/20.2.4-1/src/util/disk_cache.c/?hl=388#L388
Und drinnen util_queue_init()dann:
/* Form the thread name from process_name and name, limited to 13
* characters. Characters 14-15 are reserved for the thread number.
* Character 16 should be 0. Final form: "process:name12"
*
* If name is too long, it's truncated. If any space is left, the process
* name fills it.
*/
https://sources.debian.org/src/mesa/20.2.4-1/src/util/u_queue.c/?hl=398#L406
Daher erzeugen alle GUI-Prozesse, die diesen Mesa-Code irgendwie aufrufen, diese zusätzlichen Threads, z. B. auf einem f33-Desktopsystem von mir:
pid tid comm cls
1942 1989 gnome-s:disk$0 BAT
1942 1990 gnome-s:disk$1 BAT 1942 1991 gnome-s:disk$2 BAT
1942 1992 gnome-s:disk$3 BAT 2041 2237 Xwaylan:disk$0 BAT
2041 2238 Xwaylan:disk$1 BAT 2041 2239 Xwaylan:disk$2 BAT
2041 2240 Xwaylan:disk$3 BAT 2041 2259 Xwaylan:disk$0 BAT
2041 2260 Xwaylan:disk$1 BAT 2041 2261 Xwaylan:disk$2 BAT
2041 2262 Xwaylan:disk$3 BAT 2292 2325 gsd-xse:disk$0 BAT
2292 2326 gsd-xse:disk$1 BAT 2292 2327 gsd-xse:disk$2 BAT
2292 2328 gsd-xse:disk$3 BAT 2307 2344 ibus-x1:disk$0 BAT
2307 2345 ibus-x1:disk$1 BAT 2307 2346 ibus-x1:disk$2 BAT
2307 2347 ibus-x1:disk$3 BAT 2464 2578 firefox:disk$0 BAT
2464 2579 firefox:disk$1 BAT 2464 2580 firefox:disk$2 BAT
2464 2581 firefox:disk$3 BAT 2756 2785 firefox:disk$0 BAT
2756 2786 firefox:disk$1 BAT 2756 2787 firefox:disk$2 BAT
2756 2788 firefox:disk$3 BAT 2806 2841 firefox:disk$0 BAT
2806 2842 firefox:disk$1 BAT 2806 2843 firefox:disk$2 BAT
2806 2844 firefox:disk$3 BAT 2919 3078 firefox:disk$0 BAT
2919 3079 firefox:disk$1 BAT 2919 3080 firefox:disk$2 BAT
2919 3081 firefox:disk$3 BAT 3346 3367 firefox:disk$0 BAT
3346 3368 firefox:disk$1 BAT 3346 3369 firefox:disk$2 BAT
3346 3370 firefox:disk$3 BAT 3408 3426 firefox:disk$0 BAT
3408 3427 firefox:disk$1 BAT 3408 3428 firefox:disk$2 BAT
3408 3429 firefox:disk$3 BAT 5794 5825 firefox:disk$0 BAT
5794 5826 firefox:disk$1 BAT 5794 5827 firefox:disk$2 BAT
5794 5828 firefox:disk$3 BAT 6345 6364 firefox:disk$0 BAT
6345 6365 firefox:disk$1 BAT 6345 6366 firefox:disk$2 BAT
6345 6367 firefox:disk$3 BAT 9502 9525 firefox:disk$0 BAT
9502 9526 firefox:disk$1 BAT 9502 9527 firefox:disk$2 BAT
9502 9528 firefox:disk$3 BAT 22548 22565 firefox:disk$0 BAT
22548 22566 firefox:disk$1 BAT 22548 22567 firefox:disk$2 BAT
22548 22568 firefox:disk$3 BAT 33788 33807 vlc:disk$0 BAT
33788 33808 vlc:disk$1 BAT 33788 33809 vlc:disk$2 BAT
33788 33810 vlc:disk$3 BAT 48178 74574 kwallet:disk$0 BAT
48178 74575 kwallet:disk$1 BAT 48178 74576 kwallet:disk$2 BAT
48178 74577 kwallet:disk$3 BAT 60824 60830 chromiu:disk$0 BAT
60824 60831 chromiu:disk$1 BAT 60824 60832 chromiu:disk$2 BAT
60824 60833 chromiu:disk$3 BAT 69502 69519 firefox:disk$0 BAT
69502 69520 firefox:disk$1 BAT 69502 69521 firefox:disk$2 BAT
69502 69522 firefox:disk$3 BAT
Unter Linux kann ein C- oder C++-Programm pthread_setname_np(3) - unter Verwendung des Systemaufrufs prctl (2) - verwenden, um den Thread-Namen zu ändern.
Wenn der Entwickler Ihrer Binärdatei (oder einer von Ihrem Programm verwendeten Bibliothek wie libSDL ) beschlossen hat, diese Funktion aufzurufen, ist dies normalerweise erfolgreich.
Sie können gdb(1) , strace(1) , ltrace(1) verwenden , um mehr zu untersuchen. Oder studieren Sie den Quellcode von libSDL
Wenn Sie den GCC -Compiler verwenden, kompilieren Sie Ihren C++-Code mit g++ -Wall -Wextra -g (und kompilieren Sie möglicherweise libSDL aus seinem Quellcode neu und studieren Sie zumindest seinen Quellcode, da es Open Source ist).