PID Process name?

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.

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


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?

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

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

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

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.

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.


Jules would have to make the member public.

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!

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.

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

Will be in my next check-in…

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

BTW, the code to implement it is quite simple:

#include <sys/prctl.h>

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

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

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

1 Like