How do I launch a process so that it would have a specific identifier in ps command?

UPD: I have a couple of servers running on one box. Most of them are in deployment mode. However one is in development. All servers are Pythonic and the disease is that all the servers are listed as python in ps, which makes it impossible to killall the one in development leaving others intact.

UPD: As David and GNUix suggested I created symlinks to Python interpreter and bash scripts for each server.


4 Answers 4


Creating a symlink should do the trick, however, it would be more helpful if we knew the disease and not the symptom. What exactly are you trying to do? Because there may be a better way

my weird program name
  PID TTY          TIME CMD
 7805 pts/1    00:00:00 zsh
14020 pts/1    00:00:00 0012
14021 pts/1    00:00:00 ps
(~)ln -s 0012 weird
my weird program name
  PID TTY          TIME CMD
 7805 pts/1    00:00:00 zsh
14046 pts/1    00:00:00 weird
14047 pts/1    00:00:00 ps

Update: Based on the extra information you could (I'm sure there is an easier way but its not comming to me at the moment) have your servers write out their PID to a file upon startup, then you could kill -9 | cat /var/run/devserver.pid but then that would be a programming question :)

Update again: You could also do some shell trickery to get the PID of the servers when you launch them, off the top of my head you could create a shell function called startmyserver for example that would wrap the command you use to start your servers but also capture $! to a file based upon startup name -- then we are talking about shell scripting which is 'inbounds' @ ServerFault. :-)


You could rename the binary you're going to run. You might get away just using a symlink to the binary.

If you really want to change the name, the best way is to use a simple wrapper that sets argv and then execs the process you want to run. Don't have time to give you some example code now, but shout loudly in about 10 hours and I'll see what I can do.

  • exactly my point. You need code for that (aside from renaming/(sym)linking the binary which could be problematic if it checks for argv[0]) Commented Jun 10, 2009 at 11:10
  • Some binaries won't work well if you do mostly embedded (busybox, dropbear)
    – nhed
    Commented Feb 19, 2015 at 1:30

Look at https://github.com/electrum/procname. It allows you to set the process name of any process using an anvironment variable.


Run Java with the LD_PRELOAD and PROCNAME environment variables set:

LD_PRELOAD=/path/to/libprocname.so PROCNAME=hello java -jar foo.jar


This doesn't really belong on SO because it's generic, not a language specific question.

The short answer is not easily. That is, it can't be done from within the functionality of your shell or procfs/sysfs. You will need to use an external utility to achieve it.

There is a long description on how and why here. Beware it's pretty C-centric.


They're python which changes the game. Without now being too SO, it would probably be easier to modify them to make use of this module or a similar approach.

  • touche.. I knew there was an easier way :)
    – GNUix
    Commented Jun 10, 2009 at 11:58
  • The C code is considerably more verbose than it needs to be due to the amount of outputting it does. It should be possible to shrink it down, but it's doing pretty much the same as I was suggesting. Only with some code to go with it :) The bit it's missing is the exec to run your code :) Commented Jun 10, 2009 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .