4

I have found an application which requests process information using wmi queries (all threads and more info on each thread). I modified this application to determine the CPU usage per thread. (if my application is called 'appy', then the threads are named 'appy/0', 'appy/1', ...)

My question: is there a way to easily identify these threads outside of an IDE or another debugging environment?

I know there is the NameThreadForDebugging method, but this isn't accessible outside the debugging environment.

Is there a way to assign your own thread id upon creating that thread? Or is the only way to know who is who (the threads) by creating a dictionary and write that dictionary to a file so it is externally accessible.

Thanks in advance!

0

1 Answer 1

4

No, you cannot assign your own thread ID, the thread ID is assigned to a thread by the CreateThread function and cannot be changed during its lifetime. And as you said the only way to identify thread in the external application (not a debugger) is to share the thread identification with that application somehow.

However it's not necessary to share the information through a file, you can use a shared memory block for instance. It will be much more efficient than using files.

As the reference about thread ID you can take the remark by the GetCurrentThreadId function:

Until the thread terminates, the thread identifier uniquely identifies the thread throughout the system.

Sign up to request clarification or add additional context in comments.

1 Comment

If I understood the question right a good solution is a dll which holds a common memory block with a list of threadID/threadName pairs and provides functions to works with this list for both monitored and monitoring apps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.