Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Here is an example of gravvity's suggestion:

$ MARKER=snooze sleep 120&
$ ps ew | grep -o ".*[M]ARKER=snooze"
11741 pts/2    S      0:00 sleep 120 MARKER=snooze

The e option makes ps print the environment of the process. The -o option and the regex make grep 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 a grep -v for - to eliminate the grep itself from the results.

share|improve this answer
add comment

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

share|improve this answer
    
One can also use environment variables for this - they are not dependent on Java or anything. (The downside is that child processes inherit them.) –  grawity Jan 21 '10 at 20:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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