Change process name



I would like to change name of main process, or probably main thread, in Rust. For example, if I have a tool foo and run it from shell /usr/local/bin/foo --arg1 --arg2=qwe in process viewers I will see that whole command line. What I need is to change the command line viewed to say foo is running.

For example, in Perl that can be achieved changing $0 = "foor is running".

Some items I discovered so far.

  • All command line arguments can be read with std::env::args() but those are read-only values and I think I cannot change the first most argument with std::env.
  • There is a crate prctl but it’s is not portable and works only on Linux. At least on Darwin it does not compile from the box.
  • When constructing a new thread with thread::Builder it’s possible to set it’s name but that is only for new threads and I cannot change the name of already running thread.

Could anybody point me to any portable solution which can help me please? Or maybe where to dig deeper?

Thank you.


What platforms do you want to support? Such an operation is inherently unportable (for example, I don’t think you can do this at all on Windows). My guess is that prctl is going to be your best bet.

To learn more, you could look at the perl’s source code to see what it does when you assign to $0