how to pipe PID of java app into a command?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a command that takes a pid and operates on it.
Works great.
lsof -p 1112| wc -l
But when I use the approach to pipe in the pid, that I normally use, it fails because this is a java app:
lsof -p (ps -e | grep logstash) | wc -l
it fails to work, because java apps do not show up by their name in ps -e, rather they show up as java. (Which doesn't help, because there are multiple java apps)
You can see logstash 7 up from the bottom of this output from ps aux
498 1795 16.9 50.7 551391388 12422888 ? Sl Dec14 1425:36 /usr/bin/java
root 1896 0.0 0.0 80900 3344 ? Ss Dec14 0:01 /usr/libexec/po
postfix 1901 0.0 0.0 81152 3360 ? S Dec14 0:00 qmgr -l -t fifo
root 1926 0.0 0.0 183032 1792 ? Ss Dec14 0:00 /usr/sbin/abrtd
root 1938 0.0 0.0 116880 1260 ? Ss Dec14 0:00 crond
root 1957 0.0 0.0 21108 492 ? Ss Dec14 0:00 /usr/sbin/atd
root 1992 0.0 0.0 4064 512 tty1 Ss+ Dec14 0:00 /sbin/mingetty
root 1994 0.0 0.0 4064 516 tty2 Ss+ Dec14 0:00 /sbin/mingetty
root 1996 0.0 0.0 4064 512 tty3 Ss+ Dec14 0:00 /sbin/mingetty
root 1998 0.0 0.0 4064 516 tty4 Ss+ Dec14 0:00 /sbin/mingetty
root 2000 0.0 0.0 4064 516 tty5 Ss+ Dec14 0:00 /sbin/mingetty
root 2002 0.0 0.0 4064 512 tty6 Ss+ Dec14 0:00 /sbin/mingetty
logstash 37916 10.7 2.2 4767300 553372 ? SNsl Dec19 167:39 /usr/bin/java -
root 37972 0.0 0.0 0 0 ? S Dec19 1:12 [flush-253:2]
postfix 47810 0.0 0.0 80980 3384 ? S 13:30 0:00 pickup -l -t fi
root 48006 0.0 0.0 0 0 ? S 14:00 0:00 [flush-253:3]
root 48064 0.1 0.0 104616 4592 ? Ss 14:04 0:00 sshd: root@pts/
root 48066 0.0 0.0 108352 1828 pts/0 Ss 14:04 0:00 -bash
root 48083 0.0 0.0 110240 1136 pts/0 R+ 14:05 0:00 ps aux
What is the way to grep out the pid for logstash ?
bash command-line
add a comment |Â
up vote
1
down vote
favorite
I have a command that takes a pid and operates on it.
Works great.
lsof -p 1112| wc -l
But when I use the approach to pipe in the pid, that I normally use, it fails because this is a java app:
lsof -p (ps -e | grep logstash) | wc -l
it fails to work, because java apps do not show up by their name in ps -e, rather they show up as java. (Which doesn't help, because there are multiple java apps)
You can see logstash 7 up from the bottom of this output from ps aux
498 1795 16.9 50.7 551391388 12422888 ? Sl Dec14 1425:36 /usr/bin/java
root 1896 0.0 0.0 80900 3344 ? Ss Dec14 0:01 /usr/libexec/po
postfix 1901 0.0 0.0 81152 3360 ? S Dec14 0:00 qmgr -l -t fifo
root 1926 0.0 0.0 183032 1792 ? Ss Dec14 0:00 /usr/sbin/abrtd
root 1938 0.0 0.0 116880 1260 ? Ss Dec14 0:00 crond
root 1957 0.0 0.0 21108 492 ? Ss Dec14 0:00 /usr/sbin/atd
root 1992 0.0 0.0 4064 512 tty1 Ss+ Dec14 0:00 /sbin/mingetty
root 1994 0.0 0.0 4064 516 tty2 Ss+ Dec14 0:00 /sbin/mingetty
root 1996 0.0 0.0 4064 512 tty3 Ss+ Dec14 0:00 /sbin/mingetty
root 1998 0.0 0.0 4064 516 tty4 Ss+ Dec14 0:00 /sbin/mingetty
root 2000 0.0 0.0 4064 516 tty5 Ss+ Dec14 0:00 /sbin/mingetty
root 2002 0.0 0.0 4064 512 tty6 Ss+ Dec14 0:00 /sbin/mingetty
logstash 37916 10.7 2.2 4767300 553372 ? SNsl Dec19 167:39 /usr/bin/java -
root 37972 0.0 0.0 0 0 ? S Dec19 1:12 [flush-253:2]
postfix 47810 0.0 0.0 80980 3384 ? S 13:30 0:00 pickup -l -t fi
root 48006 0.0 0.0 0 0 ? S 14:00 0:00 [flush-253:3]
root 48064 0.1 0.0 104616 4592 ? Ss 14:04 0:00 sshd: root@pts/
root 48066 0.0 0.0 108352 1828 pts/0 Ss 14:04 0:00 -bash
root 48083 0.0 0.0 110240 1136 pts/0 R+ 14:05 0:00 ps aux
What is the way to grep out the pid for logstash ?
bash command-line
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a command that takes a pid and operates on it.
Works great.
lsof -p 1112| wc -l
But when I use the approach to pipe in the pid, that I normally use, it fails because this is a java app:
lsof -p (ps -e | grep logstash) | wc -l
it fails to work, because java apps do not show up by their name in ps -e, rather they show up as java. (Which doesn't help, because there are multiple java apps)
You can see logstash 7 up from the bottom of this output from ps aux
498 1795 16.9 50.7 551391388 12422888 ? Sl Dec14 1425:36 /usr/bin/java
root 1896 0.0 0.0 80900 3344 ? Ss Dec14 0:01 /usr/libexec/po
postfix 1901 0.0 0.0 81152 3360 ? S Dec14 0:00 qmgr -l -t fifo
root 1926 0.0 0.0 183032 1792 ? Ss Dec14 0:00 /usr/sbin/abrtd
root 1938 0.0 0.0 116880 1260 ? Ss Dec14 0:00 crond
root 1957 0.0 0.0 21108 492 ? Ss Dec14 0:00 /usr/sbin/atd
root 1992 0.0 0.0 4064 512 tty1 Ss+ Dec14 0:00 /sbin/mingetty
root 1994 0.0 0.0 4064 516 tty2 Ss+ Dec14 0:00 /sbin/mingetty
root 1996 0.0 0.0 4064 512 tty3 Ss+ Dec14 0:00 /sbin/mingetty
root 1998 0.0 0.0 4064 516 tty4 Ss+ Dec14 0:00 /sbin/mingetty
root 2000 0.0 0.0 4064 516 tty5 Ss+ Dec14 0:00 /sbin/mingetty
root 2002 0.0 0.0 4064 512 tty6 Ss+ Dec14 0:00 /sbin/mingetty
logstash 37916 10.7 2.2 4767300 553372 ? SNsl Dec19 167:39 /usr/bin/java -
root 37972 0.0 0.0 0 0 ? S Dec19 1:12 [flush-253:2]
postfix 47810 0.0 0.0 80980 3384 ? S 13:30 0:00 pickup -l -t fi
root 48006 0.0 0.0 0 0 ? S 14:00 0:00 [flush-253:3]
root 48064 0.1 0.0 104616 4592 ? Ss 14:04 0:00 sshd: root@pts/
root 48066 0.0 0.0 108352 1828 pts/0 Ss 14:04 0:00 -bash
root 48083 0.0 0.0 110240 1136 pts/0 R+ 14:05 0:00 ps aux
What is the way to grep out the pid for logstash ?
bash command-line
I have a command that takes a pid and operates on it.
Works great.
lsof -p 1112| wc -l
But when I use the approach to pipe in the pid, that I normally use, it fails because this is a java app:
lsof -p (ps -e | grep logstash) | wc -l
it fails to work, because java apps do not show up by their name in ps -e, rather they show up as java. (Which doesn't help, because there are multiple java apps)
You can see logstash 7 up from the bottom of this output from ps aux
498 1795 16.9 50.7 551391388 12422888 ? Sl Dec14 1425:36 /usr/bin/java
root 1896 0.0 0.0 80900 3344 ? Ss Dec14 0:01 /usr/libexec/po
postfix 1901 0.0 0.0 81152 3360 ? S Dec14 0:00 qmgr -l -t fifo
root 1926 0.0 0.0 183032 1792 ? Ss Dec14 0:00 /usr/sbin/abrtd
root 1938 0.0 0.0 116880 1260 ? Ss Dec14 0:00 crond
root 1957 0.0 0.0 21108 492 ? Ss Dec14 0:00 /usr/sbin/atd
root 1992 0.0 0.0 4064 512 tty1 Ss+ Dec14 0:00 /sbin/mingetty
root 1994 0.0 0.0 4064 516 tty2 Ss+ Dec14 0:00 /sbin/mingetty
root 1996 0.0 0.0 4064 512 tty3 Ss+ Dec14 0:00 /sbin/mingetty
root 1998 0.0 0.0 4064 516 tty4 Ss+ Dec14 0:00 /sbin/mingetty
root 2000 0.0 0.0 4064 516 tty5 Ss+ Dec14 0:00 /sbin/mingetty
root 2002 0.0 0.0 4064 512 tty6 Ss+ Dec14 0:00 /sbin/mingetty
logstash 37916 10.7 2.2 4767300 553372 ? SNsl Dec19 167:39 /usr/bin/java -
root 37972 0.0 0.0 0 0 ? S Dec19 1:12 [flush-253:2]
postfix 47810 0.0 0.0 80980 3384 ? S 13:30 0:00 pickup -l -t fi
root 48006 0.0 0.0 0 0 ? S 14:00 0:00 [flush-253:3]
root 48064 0.1 0.0 104616 4592 ? Ss 14:04 0:00 sshd: root@pts/
root 48066 0.0 0.0 108352 1828 pts/0 Ss 14:04 0:00 -bash
root 48083 0.0 0.0 110240 1136 pts/0 R+ 14:05 0:00 ps aux
What is the way to grep out the pid for logstash ?
bash command-line
edited Dec 20 '17 at 22:09
asked Nov 29 '17 at 21:16
samsmith
4231514
4231514
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05
add a comment |Â
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
You can hack around the problem, by passing a random option to the process when starting it like this:
$ ls
Hello.class
$ java -Dprocess_name=Logstash_or_whatever Hello
$ ps -e | grep process_name=Logstash_or_whatever
What do you think? Ugly but workable?
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see inps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...
â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
add a comment |Â
up vote
0
down vote
accepted
We established two solutions:
var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l
or, more hack,
ls -al /proc/`pgrep -f logstash`/fd |wc -l
Note the use of back ticks.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You can hack around the problem, by passing a random option to the process when starting it like this:
$ ls
Hello.class
$ java -Dprocess_name=Logstash_or_whatever Hello
$ ps -e | grep process_name=Logstash_or_whatever
What do you think? Ugly but workable?
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see inps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...
â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
add a comment |Â
up vote
1
down vote
You can hack around the problem, by passing a random option to the process when starting it like this:
$ ls
Hello.class
$ java -Dprocess_name=Logstash_or_whatever Hello
$ ps -e | grep process_name=Logstash_or_whatever
What do you think? Ugly but workable?
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see inps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...
â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can hack around the problem, by passing a random option to the process when starting it like this:
$ ls
Hello.class
$ java -Dprocess_name=Logstash_or_whatever Hello
$ ps -e | grep process_name=Logstash_or_whatever
What do you think? Ugly but workable?
You can hack around the problem, by passing a random option to the process when starting it like this:
$ ls
Hello.class
$ java -Dprocess_name=Logstash_or_whatever Hello
$ ps -e | grep process_name=Logstash_or_whatever
What do you think? Ugly but workable?
answered Nov 29 '17 at 21:48
Tomáà ¡ PospÃà ¡ek
542110
542110
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see inps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...
â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
add a comment |Â
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see inps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...
â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Interesting, but a non starter in the real world of production machines.
â samsmith
Nov 29 '17 at 21:56
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see in
ps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
Well, I live in the same world of braindead production java applications that feel like their creators have yet to see their first live Unix shell. That said, what you can do is talk to your production/applications people to get a clue. The other thing you can do is to try to find a regex that matches what you can see in
ps -e. And yet another thing is to find the file that contains the PID since at most Java applications are at least as sane to have a start script that saves their PID somewhere in a file...â Tomáà ¡ PospÃà ¡ek
Nov 29 '17 at 22:03
add a comment |Â
up vote
0
down vote
accepted
We established two solutions:
var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l
or, more hack,
ls -al /proc/`pgrep -f logstash`/fd |wc -l
Note the use of back ticks.
add a comment |Â
up vote
0
down vote
accepted
We established two solutions:
var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l
or, more hack,
ls -al /proc/`pgrep -f logstash`/fd |wc -l
Note the use of back ticks.
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
We established two solutions:
var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l
or, more hack,
ls -al /proc/`pgrep -f logstash`/fd |wc -l
Note the use of back ticks.
We established two solutions:
var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l
or, more hack,
ls -al /proc/`pgrep -f logstash`/fd |wc -l
Note the use of back ticks.
answered Dec 22 '17 at 15:25
samsmith
4231514
4231514
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407830%2fhow-to-pipe-pid-of-java-app-into-a-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
How do you know that 1112 is the right pid?
â Jeff Schaller
Nov 29 '17 at 22:05