I have a Linux Qt application that creates some QThreads
.
I know that when you create a thread it inherits the parent name and I can see it when I use htop
or ps ax -L
.
Is it possible to name those QThreads and see their names via a bash command like ps ax -L
or htop
?
Yes just give the name to the QThread object before starting it:
QThread* thr = new QThread(this);
thr->setObjectName("worker thread");
in the docs:
To choose the name that your thread will be given (as identified by the command ps -L on Linux, for example), you can call setObjectName() before starting the thread. If you don't call setObjectName(), the name given to your thread will be the class name of the runtime type of your thread object (for example, "RenderThread" in the case of the Mandelbrot Example, as that is the name of the QThread subclass). Note that this is currently not available with release builds on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With