So the problem I want to find a tidy solution for is that when I log into a server (I have some Solaris and RHEL instances about), I try to find out what applications are running:
$ ps -auxww | grep <thing I look for, usually Java>
And I get a nice list of processes, PIDs, extra details, and with the entire process name and parameters that executed with it. While this generally provides enough information for me to find out what is running, some servers are run differently. I might have a server that has multiple instances of an app server used for different purposes. Other processes are remnants of a hung process that I have mixed with non-frozen processes. I don't want to shut down all java instances because I can't find out which process needs killing.
The solution I'd like to provide is during my start-up scripts, I'd like to prepend or append to a process some text that lets me throw a short description in. Is there anything that might let me do this?
If what I'm asking sounds impossible/silly/completely-off-his-rocker, I am open to alternate solutions that give me some ability to accomplish the same thing. I'm open for ideas, but this one popped up as being doable.
It sounds like you want to uniquely tag each process so that you can discover it easily. I actually heard of that being done at a large corp by their monitoring team - every app got a unique code that could be easily found with a ps and grep.
On java you can use -D to set any variable, so you could easily just add something like "-Dmonitoringid=". The process would ignore it, but you can easily grep for it.
Alternatively, you can split out your app servers to each run under an ID specific to the application being served. We currently run a large farm of J2EE app servers, with many apps on each box, however, each runs under it's own ID to split out ownership, access, controls, etc.
This also means finding any given app server on a host is as simple as:
ps <whichever ps args you like best> | grep java | grep <uid> | grep -v grep
Here is an example of gravvity's suggestion:
The
e
option makesps
print the environment of the process. The-o
option and the regex makegrep
chop off any of the environment after the part we're searching for, but I wouldn't bet on it always having results this clean (more of the environment might get printed). Putting part of the pattern in square brackets performs the function that people often use agrep -v
for - to eliminate thegrep
itself from the results.