Is it possible to name a QThread? - rename

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.

Related

Add linked list with special processes in kernel (linux)

I want to add a linked list in kernel (linux) that is recognised by init process , I can add processes to it by adding system call , and they should be deleted from the list automatically when their parent wait for them .
I think about adding linked list as field in task_struct .
Can you help me in deleting the process from this linked list after it’s parent wait for it . I think that I should do this in release task function ...

Groovy lanaguge - How to destroy/switch to an application

I'm using the groovy language in robotic application (RPA Express). I can not figure out how to do two things in the groovy language.
I start an application with these command:
def proc = new ProcessBuilder( args )
Process process = proc.start()
My questions are:
How do I close this application? (I want to close the application at the end of the script)?
How do I switch to this application window? (I want to be sure the application window is always focused)?
Both depend on the OS.
You need to invoke a kill task command to kill the process by its pid (e.g. kill on Linux). As Joachim mentions in the comments, Process has destroy() and destroyForcibly().
You need to use the window manager API to focus the window of the given pid you want.

Windows Environment Variables - Troubling accessing updated environment variables in program

I have wrote an initialization script that sets user environment variables which are keys that have been hashed and encrypted...Once the keys have been created the key encryption exe is no longer required. I want to launch the main application and remove the init file containing the hashing and key encryption functions.
I am not having any trouble with any of the above...Everything works as should when independent of each other. The problem is that in order for the main application to have access to the newly created environment variables I need the init script to completely exit...
Everything I have tried, Popen with flags, os.system() and others have still left me in a situation where the parent process ends and the main application launches, however, the environment variables have not updated...I close and relaunch main.py and...boom the program sees the updated variables and all is fine.
All I want is the init script to run, spawn a new process that is not linked at all with init.py and then exit so it can be removed. I thought this would be simple but after many hours of head scratching and trying numerous things, I am still no closer.
If I have to I will simply bundle it as two separate .exe files but I wanted it to be a one click install type thing.
I am running windows 10 and this can be platform specific.
Links looked at:
How to stop/terminate a python script from running?
Using a Python subprocess call to invoke a Python script
Starting a separate process
https://docs.python.org/2/library/subprocess.html
Python: Howto launch a full process not a child process and retrieve the PID
And more...
Current closest result
p = Popen(["python","UserInterface.py"], stdin=PIPE, stdout=PIPE, stderr=PIPE,
creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
Create an environment block, set the environment variable using SetEnvironmentVariable, and use CreateProcess to specify this environment block for the created process.
MSDN DOC:
To specify a different environment for a process, create a new
environment block and pass the pointer to it as a parameter to the
CreateProcess function.
...
To programmatically add or modify system environment variables, add
them to the
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE
message with lParam set to the string "Environment". This allows
applications, such as the shell, to pick up your updates.

How to Launch a function using threads in Perl

I have tried to call a function using threads using perl in my windows system.
But, during the execution, when i click the button to create a thread process, Microsoft error message is displayed as shown below,
"Perl Command Line Interpreter.
Please tell Microsoft about this problem."
Code Snippet i used in Perl:
use threads;
##### Creation of a dialog box using Tkx Module #####
$Run = $MainFrame -> new_ttk__button(
-text => TEXT,
-width => 15,
-command => sub
{
threads -> create({"stack_size" => 64*4096,
"exit" => "thread_only"},
\&CALLING_FUNCTION);
}
);
It looks like Tk having difficulties with threads: Perl Update UI on Long Thread
You need to create your thread before the Tk objects, maybe it is going to work this way.
However, using threads with Tkx may be dicey. I was getting segfaults
when I tried to join the thread rather than detach it, and I get a
segfault with the code below if I move my $t inside startWork(). This
discussion suggests that you may need to start the thread before
creating any Tk widgets for it to work reliably.
Your problem comes because you are letting Tk code get copied into
your thread, by starting it late in the script. When a thread gets
launched, a copy of the main thread is made, so if there are Tk
widgets already in existence, they get copied in. Even if you don't
use the Tk code in the thread, it can cause problems, and will be
unreliable. So...... create your thread first, before starting any Tk
widget code.

What is the XDG_SESSION_COOKIE environment variable for?

I've been fighting with crontab recently because in Intrepid the gconftool uses a dbus backend, and that means that when used from crontab it doesn't work.
To make it work I have had to export the relevant environment variables when I log in so that it finds the dbus session address when the cron comes to run.
Out of curiosity I wondered what environment the cron could see and it turns out all I have is HOME, LOGNAME, PATH, SHELL, CWD and this new one on me, XDG_SESSION_COOKIE. This looks curious and several googlings have thrown up a number of bugs or other feature requests involving it but nothing that tells me what it does.
My instinct is that this variable can be used to find all the stuff that I've had to export to the file that I source before the cron job runs.
My questions, therefore, are a) can I? b) if so, how? and c) what (else) does it do?
Thanks all
This is very interesting. I found out it is the display manager setting a cookie. That one can be used to register processes to belong to a "session" which are managed by a daemon called ConsoleKit. That is to support fast user switching. My KDE4.2.1 system apparently supports it too.
Read this fedora wiki entry.
So this environment variable is like DBUS_SESSION_BUS_ADDRESS to give access to some entity (in the case of XDG_SESSION_COOKIE a login-session managed by ConsoleKit). For example having that environment variable in place, you can ask the manager for your current session:
$ dbus-send --print-reply --system --type=method_call \
--dest=org.freedesktop.ConsoleKit \
/org/freedesktop/ConsoleKit/Manager \
org.freedesktop.ConsoleKit.Manager.GetCurrentSession
method return sender=:1.1 -> dest=:1.34 reply_serial=2
object path "/org/freedesktop/ConsoleKit/Session1"
$
The Manager also supports querying for the session some process belongs to
$ [...].Manager.GetSessionForUnixProcess uint32:4494
method return sender=:1.1 -> dest=:1.42 reply_serial=2
object path "/org/freedesktop/ConsoleKit/Session1"
However, it does not list or somehow contain variables that is related to some cron job. However, documentation of dbus-launch says that libdbus will automatically find the right DBUS bus address. For example, files are stored in /home/js/.dbus/session-bus that contain the correct current dbus session addresses.

Resources