linux - How to pgrep over ssh, or use pgrep as a larger bash command? -


i'd run pgrep find id of process. works great, except when run larger bash command pgrep match it's parent shell/bash process includes match expression part of command-line.

pgrep sensibly excludes own pid results, less sensibly, doesn't seem have option exclude parent process(es).

anyone come across , have workaround.

update.

pgrep -lf java || true 

works fine, but

bash -c "(pgrep -lf java || true)" echo 'bash -c "(pgrep -lf java || true)"' | ssh <host>   

also identify parent bash process.

i'm using pgrep part of larger system, why madness.

i ran issue using python's os.system(command) executes command in subshell.

pgrep not match itself, match it's parent shell includes pgrep's arguments.

i found solution:

pgrep -f the-arguments-here[^\[] 

the [^\[] regex assures not match [ (the beginning of regex itself) , excludes parent shell.


example:

$ sh -c "pgrep -af the-arguments-here"  12345 actual-process the-arguments-here 23456 sh -c pgrep -af the-arguments-here 

vs:

$ sh -c "pgrep -af the-arguments-here[^\[]"  12345 actual-process the-arguments-here 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -