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
Post a Comment