I am a newbie to linux. I am trying to find a command that displays
pid and java class.
I tried:
ps -C java -o pid
but it only showed me pid, not java classes.
So I used a different command:
ps -ef | grep java"
It showed me a full library of JAR files and associated java classes. However, I don't need all of that information, I need only to display pid and java class.
The problem that I am facing is that sometimes the java processes take like 100M of memory and I can only know the pid with the command java on it by using linux command:
top
But it couldn't find which java program is the one responsible for this. It will help me to debug that java file for memory leak.
ps aux | grep java
try this command and you can list of java process.
[or]
JPS will be helpful
JPS,JSTAT,JMAP,JSTACK,JHAT
you can run jps command it will show the pid value and based on these pid value others command will be executed.
Use java's jps command available from Sun Java.
Related
Here are the commands I am familiar with that do what you may think I want:
For the sake of this question; "pn" = "process name"
pgrep pn
sudo /sbin/service pn status
ps -fC pn
The problem I am running into is Java. pgrep Java will give me the PID of all java processes. But if I know the exact name of a java application, let's call it coffee, pgrep Coffee gives me nothing. However, sudo /sbin/service Coffee status will give me the exact PID of Coffee. The problem is that I don't want and cannot use sudo in the script I am writing. So how do I find Coffee's PID even though it's a Java app?
I have the same problem. There might be better answers but what I do is this
ps -efw | grep pn
Then I can use awk to get just the column I want so that its just the pid.
ps -efw | grep pn | awk '{print $2}'
EDIT: Use the 'w' option in ps to get a wide output. Sometimes the name does not show up without the 'w' there.
w Wide output. Use this option twice for unlimited width.
Use this command
ps -ef| grep Coffee
You might want to look at the JPS (Java Process Status) tool. I can't remember if it comes with the runtime environment or not. It list out all currently running java processes, their PIDs, and the name of the Java application. You can probably parse the output to get the values you're looking for.
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html
Sample output:
jps
18027 Java2Demo.JAR
18032 jps
18005 jstat
I am trying to find the PID of a java webapp on a Mac. More specifically, I am trying to find the PID for a jetty webapp running on my Desktop. I have tried using Activity monitor and searched online all to no avail.
you can use jps, the Java Process Status tool:
jps
which will show you, for example:
13651 RemoteMavenServer
on my mac, jps lives in:
/usr/bin/jps
Open a terminal and type jps -v
Try to use ps aux | grep APP_NAME in Terminal.
This works for me
pgrep -f jetty
My goal is to list to STDOUT the class files and .jar files being executed by java on a Linux server. I could do some getopts thing to get args to -jar, but other processes identified by
ps -ef | grep java or ps -eo args | grep java
might be executing a class file, e.g. java -classpath /a/b/c myclass A1 A2 . I am concerned that I am looking at an inelegant solution full of lengthy piplines of greps and awk's to solve what should be (I think) a straightforward query. Given that:
some calls are made to just 'java' and others to the fully qualified pathname for java,
a variety of different (or no) java options may be set on the command line for running a process,
some processes call .jar files, some call .class files, and
there may be args to the class,
what is the best way to get a simple list of running java executables, like:
abc.jar
mymainclass
xyz.jar
numainclass
I think that this may be a not uncommon question, but I can't seem to build a search string that locates any previous discussion here. An elegant solution would be nice; right now I am looking at grepping '-jar' entries to a getops call, and parsing the remainder considering all possible combinations. I am working on a solution in bash 3.x
Thanks!
The jps command introduced in jdk5 might be what you are looking for. Using the -l and -m options it will output the pid main class and arguments. Adding -v will add the vm arguments.
This option lists all Java files currently opened by a java command. Maybe it is useful to you.
lsof | grep -E "^java.*(.jar|.class)$" | sed -E "s/\s+/\t/g" | cut -f9
It works in Debian.
How can I find out the pid of a running equinox instance, is there a pid file somewhere or is it configurable where it places a pid file?
UPDATE: to make it clear, I have a bunch of instances running, and they are configured roughly the same, so any user only looking for equinox will not know which instance is which
Just execute the following command from CLI:
ps aux | grep equinox
[EDIT]
Does equinox bind to some port?
If so, for multiple instances you can recognize the one you are interested in basis on port to which it is bound:
sudo netstat -npa |grep equinox
No, Equinox does not create a PID file or report its PID.
You could write a bundle that does this for you, but be aware that there is no standard way for a Java program to retrieve its PID (because some target operating systems don't even have the concept of "PID"). See this post for some ideas.
$ pidof equinox
From the man page:
PIDOF(8) Linux System Administrator's Manual PIDOF(8)
NAME
pidof -- find the process ID of a running program.
SYNOPSIS
pidof [-s] [-c] [-x] [-o omitpid] [-o omitpid..] program [program..]
DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints
those id's on the standard output. This program is on some systems used
in run-level change scripts, especially when the system has a System-V
like rc structure. In that case these scripts are located in
/etc/rc?.d, where ? is the runlevel. If the system has a start-stop-
daemon (8) program that should be used instead.
OPTIONS
-s Single shot - this instructs the program to only return one pid.
-c Only return process ids that are running with the same root
directory. This option is ignored for non-root users, as they
will be unable to check the current root directory of processes
they do not own.
-x Scripts too - this causes the program to also return process
id's of shells running the named scripts.
-o omitpid
Tells pidof to omit processes with that process id. The special
pid %PPID can be used to name the parent process of the pidof
program, in other words the calling shell or shell script.
EXIT STATUS
0 At least one program was found with the requested name.
1 No program was found with the requested name.
jps.exe which found on JDK 1.5 and later could monitor all Java process but is there a way to detect the specify command line and terminate the correct pid?
What if the user have JRE, is there a similar code allow us to terminate any process easily?
Prefer to keep the topic on Windows which I am working on.
The jps command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.
-q Suppress the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local VM identifiers.
-m Output the arguments passed to the main method. The output may be null for embedded JVMs.
-l Output the full package name for the application's main class or the full path name to the application's JAR file.
-v Output the arguments passed to the JVM.
-V Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags= argument).
Pipe the output of jps to grep or sed or awk or perl or even another Java program for further matching, parsing and action. On Windows, the easiest way to get those utilities is through Cygwin.
Here are some Microsoft downloadable command line utilities which are useful for working with processes on Windows:
pskill
pslist
and the rest of the Sysinternals Suite
If the user don't have jps, you can use ps. The command line options for ps differs between platforms, see man ps on you system. I use ps -C java -o pid,time,cmd to list java processes on a CentOS system. Then kill to terminate.