PID Process name?


#1

When I launch my app it gets listed by the ps command as

‘Juce Message Th’

I would like my application PID to be the same name as my application, is there an easy fix for this? Thanks.


#2

Call juce::Thread::setCurrentThreadName() with the string of your choice. That’s how Juce does it.

juce_MessageManager.cpp:

MessageManager::MessageManager() noexcept
  : quitMessagePosted (false),
    quitMessageReceived (false),
    messageThreadId (Thread::getCurrentThreadId()),
    threadWithLock (0)
{
    if (JUCEApplication::isStandaloneApp())
        Thread::setCurrentThreadName ("Juce Message Thread");
}

Also, where’s your helmet?


#3

Thanks I’ll look into that, I may get back to you.

The helmet is there , you just can’t see it.


#4

How do I get access to the setCurrentThreadName() method? Its private. I don’t want to go changing Juce sources. What’s the trick?


#5

Well juce calls setCurrentThreadName() for your thread using the name passed in to the thread constructor, so just give your Thread an appropriate name in the constructor and it will call it for you.


#6

The thing is I’m not using Juce::Thread anywhere in my code. I’m sure lots of Juce classes use it internally but I’m not using any directly in my code. I assume it’s the main application thread that determines the PID. I need to somehow get access to this no? and change it’s thread name somehow? Thanks for the help, it’s much appreciated.

Rory.


#7

Jules would have to make the member public.


#8

Hmm. TBH I’m a bit surprised that the thread name is showing up as the process’s name! I guess on linux, threads and processes blur into one. It’s a good request, I’ll make that member public!


#9

This will actually be pretty damn handy, as I have 20+ threads in my app, most of them are unique (i.e. different entry points), and I re-use threads instead of creating and destroying new ones (since I am using RAII) so the names in the debugger are usually wrong.


#10

Sweet. Thanks guys. Can you let me know when it’s ready so I can update my sources.


#11

Will be in my next check-in…


#12

setThreadName is not implemented in linux, at least in my version.

BTW, the code to implement it is quite simple:

#include <sys/prctl.h>

#if JUCE_LINUX
   // Must be called in the thread itself
   prctl(PR_SET_NAME, "ThreadName with 16-char max");
#endif

Edit: Bah, it’s in the Git already…


#13

Don’t blink. Never blink. Jules only checks in the code you’re posting about when you blink.