I need to find the pid of a certain java process in bash on linux.
If there's only one java process,
PID=$(pgrep java)
works.
For multiple java processes it becomes more complicated. Manually, I run pstree, find the ancestor of the java process that I need first, then find the java process in question. Is it possible to do this in bash? Basically I need the functionality that in pseudo-code looks like:
Having `processname1` and `processname2`
and knowing that `processname2` is in the subtree of 'processname1',
find the pid of `processname2`.
In this example the java process will be processname2
.