I have a bunch of redis service instances, and I would like to add a label to them in the output of the ps command. Currently I see:

$ ps aux | grep redis
root     <snipped>   /usr/local/bin/redis-server *:6381                    
root     <snipped>   /usr/local/bin/redis-server *:6380  

Is there a way to have an output like this:

root     <snipped>   /usr/local/bin/redis-server *:6381 item cache # <== label
root     <snipped>   /usr/local/bin/redis-server *:6380 page cache # <== label

i.e. adding a text label to easily identify what each of those instances is for.

Is there a way to do this instead of having to make copies of the binary?


Assuming redis-server does not have built-in support for changing its own command name after startup (some programs, especially daemons, do have such support), there are a few things you can do:

  • Use an alternate command name.

    Although the first argument in the command line (argv[0]) is normally the name of the binary used to invoke a command (either its full path name or its base name), it doesn't have to be. And if it isn't, then the application itself probably won't notice or care. But shells launch commands with argv[0] set following this convention so you have to launch it in a "special" way.

    To do this, you would probably want to modify the /etc/init.d script that launches this daemon.

  • Make hard links to the binary and launch those. This is similar to your suggestion of copying the binary, but copies are unnecessary. If you use hard links, the binary will not occupy any additional disk space and the code (text) of the multiple instances will all share memory, which won't happen with copies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.