├── .gitignore ├── LICENSE ├── Makefile ├── README.md └── procname.c /.gitignore: -------------------------------------------------------------------------------- 1 | libprocname.so 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining 2 | a copy of this software and associated documentation files (the 3 | "Software"), to deal in the Software without restriction, including 4 | without limitation the rights to use, copy, modify, merge, publish, 5 | distribute, sublicense, and/or sell copies of the Software, and to 6 | permit persons to whom the Software is furnished to do so, subject to 7 | the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be 10 | included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 13 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 14 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 16 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 18 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Werror -fPIC -shared 2 | 3 | TARGET=libprocname.so 4 | 5 | .PHONY: all clean 6 | 7 | all: 8 | $(CC) $(CFLAGS) -o $(TARGET) procname.c 9 | chmod 644 $(TARGET) 10 | 11 | clean: 12 | rm -f $(TARGET) 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | **procname** is a simple `LD_PRELOAD` library that sets the process name on Linux to the name specified in the environment variable `PROCNAME`. This allows Java programs to show up in `top` or `ps acux` as their logical name rather than the generic `java`. It could also be useful for other language runtimes such as Python or Ruby. 4 | 5 | # Usage 6 | 7 | Run Java with the `LD_PRELOAD` and `PROCNAME` environment variables set: 8 | 9 | LD_PRELOAD=/path/to/libprocname.so PROCNAME=hello java -jar foo.jar 10 | 11 | # License 12 | 13 | This software is so simple, basically one line of code, that it hardly 14 | warrants a copyright or license. You may consider this software to be 15 | public domain, or use it under the terms of the MIT license. 16 | -------------------------------------------------------------------------------- /procname.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void __attribute__ ((constructor)) procname_init() 5 | { 6 | const char *name; 7 | if ((name = getenv("PROCNAME")) && (*name)) { 8 | prctl(PR_SET_NAME, name); 9 | } 10 | } 11 | --------------------------------------------------------------------------------