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.
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
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.
Look at https://github.com/electrum/procname. It allows you to set the process name of any process using an anvironment variable.
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.
Update:
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.